-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: 4.0.6
-
Component/s: None
-
None
-
Query Optimization
-
v4.0, v3.6
-
Query 2019-04-22
With MongoDB 3.6, dollar-prefixed fields were allowed. Invoking ReplaceOne on such a document, however, results in an error:
rs0:PRIMARY> db.coll.insertOne({"a": {"$foo": 1}}) { "acknowledged" : true, "insertedId" : ObjectId("5c86835900b48b0b86ee197d") } rs0:PRIMARY> doc = db.coll.findOne() { "_id" : ObjectId("5c86835900b48b0b86ee197d"), "a" : { "$foo" : 1 } } rs0:PRIMARY> doc { "_id" : ObjectId("5c86835900b48b0b86ee197d"), "a" : { "$foo" : 1 } } rs0:PRIMARY> doc['b'] = 2 2 rs0:PRIMARY> db.coll.replaceOne({}, doc) 2019-03-11T11:49:14.749-0400 E QUERY [js] WriteError: The dollar ($) prefixed field '$foo' in 'a.$foo' is not valid for storage. : WriteError({ "index" : 0, "code" : 52, "errmsg" : "The dollar ($) prefixed field '$foo' in 'a.$foo' is not valid for storage.", "op" : { "q" : { }, "u" : { "_id" : ObjectId("5c86835900b48b0b86ee197d"), "a" : { "$foo" : 1 }, "b" : 2 }, "multi" : false, "upsert" : false } }) WriteError@src/mongo/shell/bulk_api.js:461:48 Bulk/mergeBatchResults@src/mongo/shell/bulk_api.js:841:49 Bulk/executeBatch@src/mongo/shell/bulk_api.js:906:13 Bulk/this.execute@src/mongo/shell/bulk_api.js:1150:21 DBCollection.prototype.replaceOne@src/mongo/shell/crud_api.js:489:17 @(shell):1:1
This happened on MongoDB 4.0.5, but probably happens on all versions. This smells of a validation that should have been removed in 3.6 when these field names were allowed.
I can't think of any reason that documents valid for insertOne wouldn't be valid for replaceOne.
- is duplicated by
-
SERVER-56462 Field starting with dollar in an embedded document cannot be updated with $set
- Closed