Details
-
Bug
-
Resolution: Works as Designed
-
Major - P3
-
None
-
4.3.6
-
None
-
ALL
Description
Hey, this is Thomas with the Node.js driver team!
I had a user report this case and I'm passing it up. This seems like odd behavior to me, perhaps there's a way of escaping that I'm not aware of.
For some reason when updateOne is passed a pipeline that `$sets` and the values in that document start with a `$` an update does not take place, it actually removes the property if it exists. If not it will do nothing. I've tried updating strings like `a$a` and they work as expected.
Here's an example from the shell (4.3.6)
> db.meow.insert({ name: 'tom' }) |
WriteResult({ "nInserted" : 1 }) |
> const cat = db.meow.findOne() |
> db.meow.updateOne({ _id: cat._id }, [{ $set: { password: '$anything' }}]) |
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 0 } |
> db.meow.findOne()
|
{ "_id" : ObjectId("5ef65b23f330c5e7e431c975"), "name" : "tom" } |
> db.meow.updateOne({ _id: cat._id }, [{ $set: { password: 'anything' }}]) |
{ "acknowledged" : true, "matchedCount" : 1, "modifiedCount" : 1 } |
> db.meow.findOne()
|
{
|
"_id" : ObjectId("5ef65b23f330c5e7e431c975"), |
"name" : "tom", |
"password" : "anything" |
}
|