It looks like _id field has stricter rules than other fields:
> db.getMongo()._skipValidation = true true > db.user.insert({ x: { 'a.b': 1 }}) WriteResult({ "nInserted" : 1 }) > db.user.find() { "_id" : ObjectId("573a41831b3dd58ca2e7f085"), "x" : { "a.b" : 1 } } > db.user.insert({ _id: { 'a.b': 1 }}) WriteResult({ "nInserted" : 0, "writeError" : { "code" : 57, "errmsg" : "a.b is not valid for storage." } })
In more detail, the dotted field names is currently disallowed in:
- top level fields
- any level inside _id
and is allowed any other place
Also note that mongos is already relying on this behavior:
mongos> db.adminCommand({ enableSharding: 'test' }) { "ok" : 1 } mongos> db.adminCommand({ shardCollection: 'test.user', key: { 'x.y': 1 }}) { "collectionsharded" : "test.user", "ok" : 1 } mongos> use config switched to db config mongos> db.chunks.find() { "_id" : "test.user-x.y_MinKey", "ns" : "test.user", "min" : { "x.y" : { "$minKey" : 1 } }, "max" : { "x.y" : { "$maxKey" : 1 } }, "shard" : "shard0000", "lastmod" : Timestamp(1, 0), "lastmodEpoch" : ObjectId("573a41e5741a236015ac3ec9") } mongos> db.collections.find() { "_id" : "test.user", "lastmodEpoch" : ObjectId("573a41e5741a236015ac3ec9"), "lastmod" : ISODate("1970-02-19T17:02:47.296Z"), "dropped" : false, "key" : { "x.y" : 1 }, "unique" : false }
- is depended on by
-
SERVER-6999 Embedded "dot-notation" fields broken for tag based balancing
- Closed
- is related to
-
SERVER-10454 Do not store field names with "." in any metadata collections
- Closed
- related to
-
SERVER-29334 Cannot write shard chunks documents with _id fields containing values with dotted field names, e.g. { _id: { a.b: 10 } }
- Closed
-
SERVER-29594 "update" can produce documents with dotted field names
- Closed