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

Able to update documents to have $ref $id and $db fields on top level

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 2.6.4, 2.7.1
    • Component/s: Write Ops
    • Query Optimization
    • ALL

      It seems that it is possible to update illegal top level fields ($ref, $id, $db). Note that this fails if you use insert, instead of update.

      > db.test.drop()
      true
      > db.test.update({_id:0}, {_id:0, $ref: "1", $id: 1, $db:"1"}, true)
      WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : 0 })
      > db.test.findOne()
      { "_id" : 0, "$ref" : "1", "$id" : 1, "$db" : "1" }
      > db.test.insert({_id: 1, $ref: "1", $id: 1, $db: "1"})
      WriteResult({
              "nInserted" : 0,
              "writeError" : {
                      "code" : 2,
                      "errmsg" : "Document can't have $ prefixed field names: $ref"
              }
      })
      > db.test.find()
      { "_id" : 0, "$ref" : "1", "$id" : 1, "$db" : "1" }
      > db.runCommand({buildinfo:1})
      {
              "version" : "2.7.2-pre-",
              "gitVersion" : "87d09bc9cfe898f093c4d76ca5aad807c2e817e7",
              "OpenSSLVersion" : "",
              "sysInfo" : "Linux localhost.localdomain 3.13.10-200.fc20.x86_64 #1 SMP Mon Apr 14 20:34:16 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49",
              "loaderFlags" : "-fPIC -pthread -Wl,-z,now -rdynamic",
              "compilerFlags" : "-Wnon-virtual-dtor -Woverloaded-virtual -std=c++11 -fPIC -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -pipe -Werror -O3 -Wno-unused-local-typedefs -Wno-unused-function -Wno-deprecated-declarations -fno-builtin-memcmp -std=c99",
              "allocator" : "tcmalloc",
              "versionArray" : [
                      2,
                      7,
                      2,
                      -100
              ],
              "javascriptEngine" : "V8",
              "bits" : 64,
              "debug" : false,
              "maxBsonObjectSize" : 16777216,
              "ok" : 1
      }
      > 
      

            Assignee:
            backlog-query-optimization [DO NOT USE] Backlog - Query Optimization
            Reporter:
            andrew.emil@10gen.com Andrew Emil (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: