Skip to content
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

Collection.findOne(mongoQuery).populate('schema') error #10619

Closed
aurickislam opened this issue Aug 26, 2021 · 1 comment
Closed

Collection.findOne(mongoQuery).populate('schema') error #10619

aurickislam opened this issue Aug 26, 2021 · 1 comment
Milestone

Comments

@aurickislam
Copy link

aurickislam commented Aug 26, 2021

In my collection there is a property called schema.

const schema = new mongoose.Schema({
	name: {type: String, required: true},
	schema: { type: mongoose.Schema.Types.ObjectId, required: true, ref: 'Schema'},
	features: {type: Object, required: true}
}, {versionKey: false});

My code is following

const mongoQuery = {
	_id: new mongoose.Types.ObjectId(configurationId)
};

const config = await Configuration.findOne(mongoQuery).populate('schema');

While I was trying to populate the schema property it was giving the following error.

/home/mypc/nodejsprojects/my_app/node_modules/mongoose/lib/helpers/populate/getSchemaTypes.js:27
  const pathschema = schema.path(path);
                            ^

TypeError: schema.path is not a function
    at getSchemaTypes (/home/mypc/nodejsprojects/my_app/node_modules/mongoose/lib/helpers/populate/getSchemaTypes.js:27:29)
    at getModelsMapForPopulate (/home/mypc/nodejsprojects/my_app/node_modules/mongoose/lib/helpers/populate/getModelsMapForPopulate.js:57:14)
    at populate (/home/mypc/nodejsprojects/my_app/node_modules/mongoose/lib/model.js:4435:21)
    at _populate (/home/mypc/nodejsprojects/my_app/node_modules/mongoose/lib/model.js:4406:5)
    at /home/mypc/nodejsprojects/my_app/node_modules/mongoose/lib/model.js:4383:5
    at promiseOrCallback (/home/mypc/nodejsprojects/my_app/node_modules/mongoose/lib/helpers/promiseOrCallback.js:10:12)
    at Mongoose._promiseOrCallback (/home/mypc/nodejsprojects/my_app/node_modules/mongoose/lib/index.js:1151:10)
    at Function.Model.populate (/home/mypc/nodejsprojects/my_app/node_modules/mongoose/lib/model.js:4381:23)
    at /home/mypc/nodejsprojects/my_app/node_modules/mongoose/lib/query.js:2320:11
    at /home/mypc/nodejsprojects/my_app/node_modules/mongoose/lib/query.js:3108:21
    at processTicksAndRejections (internal/process/task_queues.js:77:11)

If I replace the property name from schema to configSchema or schemas or anything but schema the problem resolves.
It was working fine with the property name schema till mongoose@5.13.8. I have recently update my project with mongoose@6.0.1. And facing the issue.

@lorand-horvath
Copy link
Contributor

Perhaps this breaking change is causing it: https://mongoosejs.com/docs/migrating_to_6.html#strictpopulate

@vkarpov15 vkarpov15 added this to the 6.0.2 milestone Aug 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants