[SERVER-12852] v2.6.0-rc0 update $setOnInsert still saves invalid element names Created: 23/Feb/14  Updated: 11/Jul/16  Resolved: 24/Feb/14

Status: Closed
Project: Core Server
Component/s: Write Ops
Affects Version/s: 2.6.0-rc0
Fix Version/s: 2.6.0-rc1

Type: Bug Priority: Minor - P4
Reporter: Roman Kuzmin Assignee: Scott Hernandez (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Participants:

 Description   

Release notes say: "Starting in MongoDB version 2.5.4, update operations no longer supports saving field names that contain a dot (.) or a field name that starts with a dollar sign ($)."

There is a case where update still saves a field name with a dot (.).

The steps:

> db.test.drop()
true
 
> db.test.update({y : {"bad.1" : 1}}, {$setOnInsert : {x : 42}}, {upsert : true})
WriteResult({
        "nMatched" : 0,
        "nUpserted" : 1,
        "nModified" : 0,
        "_id" : ObjectId("530a79b4f0b65d96ef21598a")
})
 
> db.test.find()
{ "_id" : ObjectId("530a79b4f0b65d96ef21598a"), "y" : { "bad.1" : 1 }, "x" : 42 }

As a result, we have a new document which has a nested document with the element name with a dot: "bad.1".



 Comments   
Comment by Githook User [ 24/Feb/14 ]

Author:

{u'username': u'scotthernandez', u'name': u'Scott Hernandez', u'email': u'scotthernandez@gmail.com'}

Message: SERVER-12852: validate update+upsert->insert doc
Branch: master
https://github.com/mongodb/mongo/commit/93d8298778fa7f11402755bbd23d28767227f86d

Comment by Roman Kuzmin [ 23/Feb/14 ]

Yet another case with a saved element name started with ($).

If we try this with invalid name "$bad"

> db.test.update({y : {"$bad" : 1}}, {$setOnInsert : {x : 42}}, {upsert : true})

then it fails with a message "unknown operator: $bad". Good.

But if we make "$bad" nested

> db.test.update({y : {y : {"$bad" : 1}}}, {$setOnInsert : {x : 42}}, {upsert : true})
WriteResult({
        "nMatched" : 0,
        "nUpserted" : 1,
        "nModified" : 0,
        "_id" : ObjectId("530a8327f0b65d96ef2159a8")
})
 
> db.test.find()
{ "_id" : ObjectId("530a8327f0b65d96ef2159a8"), "y" : { "y" : { "$bad" : 1 } }, "x" : 42 }

then we can see that update saves this nested document with an element name "$bad".

Generated at Thu Feb 08 03:29:49 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.