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

Operation findAndModify not possible on hashed sharded collection

    • Type: Icon: Bug Bug
    • Resolution: Community Answered
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 5.0.4
    • Component/s: None
    • Server Triage
    • ALL
    • Hide

       

      db.createCollection('dummy')
      db.dummy.createIndex({ ts: "hashed" })
      sh.shardCollection(db.getName() + '.dummy', { ts: "hashed" })
      db.dummy.insertOne({ _id: 1, ts: ISODate(), a: [] })
      
      db.dummy.findOneAndUpdate(
         { _id: 1 },
         { $push: { action: { a: 1 } } },
         { returnNewDocument: true }
      )
      
      uncaught exception: Error: findAndModifyFailed failed: {
      	"ok" : 0,
      	"errmsg" : "Query for sharded findAndModify must contain the shard key",
      	"code" : 61,
      	"codeName" : "ShardKeyNotFound",
      	"$clusterTime" : {
      		"clusterTime" : Timestamp(1637567453, 1),
      		"signature" : {
      			"hash" : BinData(0,"LyZC2RQslxgP9O7xKZ6NjXFuioo="),
      			"keyId" : NumberLong("7025509753912557590")
      		}
      	},
      	"operationTime" : Timestamp(1637567453, 1)
      } :
      _getErrorWithCode@src/mongo/shell/utils.js:25:13
      DBCollection.prototype.findAndModify@src/mongo/shell/collection.js:742:15
      DBCollection.prototype.findOneAndUpdate@src/mongo/shell/crud_api.js:910:12
      @(shell):1:1
      
      

       

       

      I tried workarounds like

       

      db.dummy.findOneAndUpdate(
         { _id: 1, ts: { $lte: ISODate() } },
         { $push: { action: { a: 1 } } },
         { returnNewDocument: true }
      )
      
      db.dummy.findOneAndUpdate(
         { _id: 1, ts: { $exists: true } },
         { $push: { action: { a: 1 } } },
         { returnNewDocument: true }
      )
      
      

       

       

      But none of them is working. I don't find any possibility to query for a hashed value. Do you have any solution?

      Kind Regards
      Wernfried

       

       

      Show
        db.createCollection( 'dummy' ) db.dummy.createIndex({ ts: "hashed" }) sh.shardCollection(db.getName() + '.dummy' , { ts: "hashed" }) db.dummy.insertOne({ _id: 1, ts: ISODate(), a: [] }) db.dummy.findOneAndUpdate( { _id: 1 }, { $push: { action: { a: 1 } } }, { returnNewDocument: true } ) uncaught exception: Error: findAndModifyFailed failed: { "ok" : 0, "errmsg" : "Query for sharded findAndModify must contain the shard key" , "code" : 61, "codeName" : "ShardKeyNotFound" , "$clusterTime" : { "clusterTime" : Timestamp(1637567453, 1), "signature" : { "hash" : BinData(0, "LyZC2RQslxgP9O7xKZ6NjXFuioo=" ), "keyId" : NumberLong( "7025509753912557590" ) } }, "operationTime" : Timestamp(1637567453, 1) } : _getErrorWithCode@src/mongo/shell/utils.js:25:13 DBCollection.prototype.findAndModify@src/mongo/shell/collection.js:742:15 DBCollection.prototype.findOneAndUpdate@src/mongo/shell/crud_api.js:910:12 @(shell):1:1     I tried workarounds like   db.dummy.findOneAndUpdate( { _id: 1, ts: { $lte: ISODate() } }, { $push: { action: { a: 1 } } }, { returnNewDocument: true } ) db.dummy.findOneAndUpdate( { _id: 1, ts: { $exists: true } }, { $push: { action: { a: 1 } } }, { returnNewDocument: true } )     But none of them is working. I don't find any possibility to query for a hashed value. Do you have any solution? Kind Regards Wernfried    

      When I have a sharded collection with a hashed shard key then findAndModify does not work. I constantly get error "Query for sharded findAndModify must contain the shard key" and I find no way to get rid of it.

       

       

            Assignee:
            backlog-server-triage [HELP ONLY] Backlog - Triage Team
            Reporter:
            wernfried.domscheit@sunrise.net Wernfried Domscheit
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: