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

fix(document): avoid triggering setter when initializing Model.prototype.collection to allow defining collection as a schema path name #13968

Merged
merged 1 commit into from Oct 13, 2023

Conversation

vkarpov15
Copy link
Collaborator

Fix #13956

Summary

Right now get the following error when you try to use collection as a schema path name:

$ node gh-13956.js 
TypeError: Cannot read properties of undefined (reading 'Symbol(mongoose#Document#scope)')
    at Model.set [as collection] (/home/val/Workspace/MongoDB/mongoose/lib/helpers/document/compile.js:205:32)
    at Function.compile (/home/val/Workspace/MongoDB/mongoose/lib/model.js:4776:30)
    at Mongoose._model (/home/val/Workspace/MongoDB/mongoose/lib/index.js:620:27)
    at Mongoose.model (/home/val/Workspace/MongoDB/mongoose/lib/index.js:579:27)
    at run (/home/val/Workspace/MongoDB/troubleshoot-mongoose/gh-13956.js:11:25)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

This PR fixes that, you can now use collection as a schema name, albeit still with the "collection is a reserved schema pathname and may break some functionality." warning.

Examples

…type.collection` to allow defining `collection` as a schema path name

Fix #13956
Copy link
Collaborator

@hasezoey hasezoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

lib/model.js Show resolved Hide resolved
@vkarpov15 vkarpov15 merged commit a72c023 into master Oct 13, 2023
40 of 42 checks passed
@vkarpov15 vkarpov15 deleted the vkarpov15/gh-13956 branch October 13, 2023 13:17
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

Successfully merging this pull request may close these issues.

How can I use collection as schema property name?
2 participants