system.js fails to work seamlessly in sharded collections

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Won't Fix
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • ALL
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      (I couldn't find a duplicate but this was a known issue - please duplicate if you know of one)

      The 'system.js' collection is consulted locally on each shard, but there is no mechanism to ensure that its contents are identical on each shard. In order to use this correctly for a sharded collection, you have to directly connect to a shard and insert the same documents on each shard.

      mongos> db.adminCommand({enableSharding: "test"})
      {
              "ok" : 1,
              "$clusterTime" : {
                      "clusterTime" : Timestamp(1647270677, 3),
                      "signature" : {
                              "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                              "keyId" : NumberLong(0)
                      }
              },
              "operationTime" : Timestamp(1647270677, 2)
      }
      mongos> db.foo.find({$where: "return isTwo(this.x)"})
      mongos> db.adminCommand({shardCollection: "test.foo", key: {_id: "hashed"}})
      {
              "collectionsharded" : "test.foo",
              "ok" : 1,
              "$clusterTime" : {
                      "clusterTime" : Timestamp(1647270747, 44),
                      "signature" : {
                              "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                              "keyId" : NumberLong(0)
                      }
              },
              "operationTime" : Timestamp(1647270747, 40)
      }
      mongos> db.foo.insert([{}, {}])
      BulkWriteResult({
              "writeErrors" : [ ],
              "writeConcernErrors" : [ ],
              "nInserted" : 2,
              "nUpserted" : 0,
              "nMatched" : 0,
              "nModified" : 0,
              "nRemoved" : 0,
              "upserted" : [ ]
      })
      mongos> db.foo.find({$where: "return isTwo(this.x)"})
      Error: error: {
              "ok" : 0,
              "errmsg" : "Encountered non-retryable error during query :: caused by :: Executor error during find command :: caused by :: ReferenceError: isTwo is not defined :\n@:1:15\n",
              "code" : 139,
              "codeName" : "JSInterpreterFailure",
              "$clusterTime" : {
                      "clusterTime" : Timestamp(1647270782, 1),
                      "signature" : {
                              "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                              "keyId" : NumberLong(0)
                      }
              },
              "operationTime" : Timestamp(1647270777, 3)
      }
      mongos> db.system.js.insertOne({_id: "isTwo", value: function(x) { return x === 2 }})
      { "acknowledged" : true, "insertedId" : "isTwo" }
      mongos> db.foo.find({$where: "return isTwo(this.x)"})
      Error: error: {
              "ok" : 0,
              "errmsg" : "Encountered non-retryable error during query :: caused by :: Executor error during find command :: caused by :: ReferenceError: isTwo is not defined :\n@:1:15\n",
              "code" : 139,
              "codeName" : "JSInterpreterFailure",
              "$clusterTime" : {
                      "clusterTime" : Timestamp(1647271179, 1),
                      "signature" : {
                              "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
                              "keyId" : NumberLong(0)
                      }
              },
              "operationTime" : Timestamp(1647270818, 2)
      }
      

              Assignee:
              Garaudy Etienne
              Reporter:
              Charlie Swanson
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: