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

TypeError: model.collection.addQueue is not a function because property "collection" is overwritten when loading class and "collection" was provided in class #10254

Closed
Baumgaer opened this issue May 16, 2021 · 3 comments · Fixed by #10257
Assignees
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Milestone

Comments

@Baumgaer
Copy link

version 5.12.8 worked fine and since 5.12.9 the following bug occures when building the schemas:

TypeError: model.collection.addQueue is not a function
     at D:\Atom_projects\ba\node_modules\mongoose\lib\model.js:1693:30
     at processTicksAndRejections (internal/process/task_queues.js:75:11)

I don't know how to reproduce this, but the logging on the tracebacks given position, following will be printed:

Line of code:

model.collection.addQueue(create, []);

logging: console.log(model, model.collection, model.collection.addQueue)

Result:

THE MODEL: Model { SystemUser }
THE COLLECTION: users
THE FUNCTION: undefined

The model SystemUser is derived from Model user and both have the same collection.
The collection "users" seems to be a String instead of a "NaviveCollection"-Object

Expected behavior is to queue the collection

What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.

Node: v12.13.0
mongoose: 5.12.9
MongoDB: 4.4.2 Community

@Baumgaer
Copy link
Author

Found the reason. I had a static property called "collection" and I loaded the whole class to the model. So the loading has overwritten the models property "collection". Maybe there should be an error message which protects internal properties from overwrite or add a mapping to an alternative, internal choosen name.

@Baumgaer Baumgaer changed the title TypeError: model.collection.addQueue is not a function TypeError: model.collection.addQueue is not a function because property "collection" is overwritten when loading class and "collection" was provided in class May 17, 2021
@IslandRhythms IslandRhythms added the developer-experience This issue improves error messages, debugging, or reporting label May 17, 2021
@vkarpov15 vkarpov15 added this to the 5.12.10 milestone May 17, 2021
@vkarpov15 vkarpov15 added enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature and removed developer-experience This issue improves error messages, debugging, or reporting labels May 17, 2021
@vkarpov15
Copy link
Collaborator

Any code in model.js that uses this.collection should use this.$__collection instead, and models should have both a collection and a $__collection property that point to the underlying collection object. We should use $__collection internally to minimize risk of conflicts, but we should leave collection for backwards compatibility.

@IslandRhythms IslandRhythms linked a pull request May 17, 2021 that will close this issue
@Baumgaer
Copy link
Author

Baumgaer commented May 17, 2021

The same should be done with the property "schema" and all other properties which could be overwritten by loading a class into the schema.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This issue is a user-facing general improvement that doesn't fix a bug or add a new feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants