Should mongoose show an error/warning if trying to delete on non-existing properties?
See original GitHub issueI was deleting two models based on a given court, and noticed a discrepancy in the logs (one time ObjectId and one time string):
Mongoose: bookings.remove({ court: ObjectId("5764ceaed5b3e76b78c149e9") }) {}
Mongoose: events.remove({ court: '5764ceaed5b3e76b78c149e9' }) {}
After further investigation, I realised the difference between the two models is that for events the court
properly doesn’t exist (it should have been courts
). Should mongoose not throw an error/warning if we’re deleting on properties which are not defined on the model?
What is the expected behaviour if we do this?
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Why can't I delete a mongoose model's object properties?
Mongoose models are not javascript objects. So convert it into a javascript object and delete the property. The code should look like this:...
Read more >Mongoose v6.8.2: Schemas
The strict option, (enabled by default), ensures that values passed to our model constructor that were not specified in our schema do not...
Read more >Delete Many Documents with model.remove()
I would start with this package.json file and add mongodb@~3.6.0 and ... (node:522) Warning: Accessing non-existent property 'remove' of ...
Read more >Mistakes You're Probably Making With MongooseJS, And ...
collection('documents', function(error, collection) { collection.findOne({ _id : collection.db.bson_serializer.ObjectID.
Read more >Node.js v19.3.0 Documentation
All errors thrown by the node:assert module will be instances of the ... or not. code <string> Value is always ERR_ASSERTION to show...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
with the current mongoose version it removes those paths from the query, which could result in unwanted (and silent) behavior:
Note: the above code was run against a empty collection, that is why
deletedCount
is 0Reproduction Repository / Branch: https://github.com/typegoose/typegoose-testing/tree/mongooseGh4251
this is probably related to
strict
being default now and strict removing unknown properties (though silently)By “do nothing with them” I meant they stay in the query as is and mongoose doesn’t cast them away,