Closed spaiz closed 5 months ago
UPD
Checked non bulk query... and looks like this behaviour on regular updateOne
existed for a long time :/
await User.updateOne({ name: 'Alex', $comment: "hui" }, { name: "Alex", nickname: "aa" }, { upsert: true });
throws
MongooseError [StrictModeError]: Path "$comment" is not in schema, strict mode is `true`, and upsert is `true`.
We are lucky we don't use updateOne
a lot in our code, and we have tests which did catch this behaviour on bulkWrite
.
Maybe it should be fixed for all the cases? I mean, to allow passing $comment
?
P.S. Funny thing, .comment() allows pass value, but it is not propagated to MongoDB (a least for v5.*)
await User.updateOne({ name: 'Alex', }, { name: "Alex", nickname: "ddddddddd" }, { upsert: true }).comment("my comment");
As of March 1st, we no longer support support 5.x https://mongoosejs.com/docs/version-support.html
Didn't see that last part about the newer versions having the same issue. Sorry about that.
@IslandRhythms np. Tnx!
I wanted to try to upgrade to a newer version, but the issue exists on all the versions :/
Tried to bypass it by using { strict: false }
on the bulkWrite
method, and actually my tests got broken... took me 2 hours to understand we have a bug... and with { strict: false }
the wrong data would go to db... so I'm not fun of doing it now :/
Anyway, if it will be fixed on newer version, I'll have more reasons to push upgrade in production.
Fix will be in v6.12.9. Mongoose 5.x is no longer maintained, please check out out guide to migrating from Mongoose 5 to Mongoose 6.
Prerequisites
Mongoose version
5.9.7
Node.js version
12.x
MongoDB server version
3.5.5
Typescript version (if applicable)
No response
Description
Upgraded Mongoose to the latest 5.* version and tests failed. After diving in, I did find a breaking change which doesn't make sense to me.
This new behaviour was introduced in mongoose v5.9.7 and I think it was in this PR - https://github.com/Automattic/mongoose/issues/8698
I didn't expect the
$comment
to be interpreted as a field of the model.From MongoDB documentation (https://www.mongodb.com/docs/manual/reference/operator/query/comment/)
You can check that in mongoose v5.9.5 it will work and you will see in db logs the queries:
Steps to Reproduce
As result, it will fail with
Expected Behavior
As per mongodb documentation, $comment should be passed to MongoDB and it will be logged.
P.S. Newer versions are broken as well. Tested: 8.3.4, 7.6.11, 6.12.8