-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useDB doesn't allow to populate. #11003
Comments
"@typegoose/typegoose": "8.3.0", With the latest version of mongoose 5, the above functionality works as expected. |
reproduction code (pure mongoose, minified from example): https://github.com/typegoose/typegoose-testing/tree/verify633 checkout commit output on 6.x: baseInChanged {
something: 'helloInChanged2',
reference: new ObjectId("619cdac1ce8470ff0831ca1c"),
_id: new ObjectId("619e2ccfdc2dee0ab26e0eb6"),
__v: 0
}
MissingSchemaError: Schema hasn't been registered for model "Nested".
Use mongoose.model(name, schema)
at NativeConnection.Connection.model (/mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/connection.js:1133:11)
at addModelNamesToMap (/mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/helpers/populate/getModelsMapForPopulate.js:470:28)
at getModelsMapForPopulate (/mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/helpers/populate/getModelsMapForPopulate.js:174:7)
at populate (/mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/model.js:4445:21)
at _populate (/mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/model.js:4416:5)
at /mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/model.js:4393:5
at /mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/helpers/promiseOrCallback.js:32:5
at new Promise (<anonymous>)
at promiseOrCallback (/mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/helpers/promiseOrCallback.js:31:10)
at Mongoose._promiseOrCallback (/mnt/projects/nodejs/typegoose-testing/node_modules/mongoose/lib/index.js:1151:10) output on 5.x: baseInChanged {
_id: 619e2cf912726254c5a44501,
something: 'helloInChanged2',
reference: 619cdac1ce8470ff0831ca1c,
__v: 0
}
baseInChanged populated {
_id: 619e2cf912726254c5a44501,
something: 'helloInChanged2',
reference: 619cdac1ce8470ff0831ca1c,
__v: 0
} Note: no error, it just didnt populate note: because this was originally a typegoose issue, the code still contains typegoose things, but commented out i think this may be related to https://mongoosejs.com/docs/migrating_to_6.html#strictpopulate |
Can repro the 6.x behavior. I can't run the 5.x code cause npm throws an error saying there is conflicting dependencies |
I did a --force and was able to run it |
bug
What is the current behavior?
When we are using the useDB approach to achieve the multitenancy then the mongoose doesn't have information about the nested schema's
We are using typegoose wrapper along with mongoose
Now when we are trying to get the ref populated it says schema hasn't been registered for the "Roles", or any other ref property.
If we don't use the useDB(required for multitenancy) and just for testing we use the db name in connection string itself like mongodb://localhost:27017/theDB then it works fine.
If the current behavior is a bug, please provide the steps to reproduce.
My Model
Creating dynamic connection via DBConfigClass as below
This is how we are using this config for making dynamic connections
My starting server file looks like this
Typescript tsconfig.json
What is the expected behavior?
The expected behaviour is to populate the child objects with the useDB option. Currently the schema doesn't get registered for the referenced schemas. When we are using the actual connection string with the db name it works fine. This approach was also tested with mongoose version ~5.10.x and was working well but since stubs are gone we wanted to upgrade to the latest version.
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
NodeJS - 14.16.0
Typescript - 4.5.2
NPM - 8.1.4
"@typegoose/typegoose": "^9.1.0",
"express": "^4.17.1",
"mongoose": "^6.0.11"
The text was updated successfully, but these errors were encountered: