Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-24174

Inconsistent rule for storing dotted field names

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.6.0-rc1
    • Affects Version/s: 3.3.6
    • Component/s: Sharding, Storage
    • None
    • Fully Compatible
    • ALL
    • Query 2017-10-23

      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 }
      

            Assignee:
            nicholas.zolnierz@mongodb.com Nicholas Zolnierz
            Reporter:
            randolph@mongodb.com Randolph Tan
            Votes:
            1 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: