-
Type: Task
-
Resolution: Won't Do
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: Server
-
Labels:
-
0.25
The findAndModify documentation mentions that the query field must contain the shard key, however the requirement is more restrictive. The query field must contain an exact match on the shard key:
mongos> sh.status() --- Sharding Status --- sharding version: { "_id" : 1, "minCompatibleVersion" : 5, "currentVersion" : 6, "clusterId" : ObjectId("582614b16369490a2de6a7dc") } shards: { "_id" : "shard0000", "host" : "franklinia:20000", "state" : 1 } { "_id" : "shard0001", "host" : "franklinia:20001", "state" : 1 } active mongoses: "3.4.0-rc2-83-g54b9623" : 1 autosplit: Currently enabled: no balancer: Currently enabled: yes Currently running: no Balancer lock taken at Fri Nov 11 2016 13:57:53 GMT-0500 (EST) by ConfigServer:Balancer Failed balancer rounds in last 5 attempts: 0 Migration Results for the last 24 hours: 1 : Success 1 : Failed with error 'aborted', from shard0001 to shard0001 databases: { "_id" : "test", "primary" : "shard0000", "partitioned" : true } test.foo shard key: { "_id" : 1 } unique: false balancing: true chunks: shard0000 1 shard0001 1 { "_id" : { "$minKey" : 1 } } -->> { "_id" : 50000 } on : shard0001 Timestamp(2, 0) { "_id" : 50000 } -->> { "_id" : { "$maxKey" : 1 } } on : shard0000 Timestamp(2, 1) mongos> db.foo.findAndModify({query: {_id: {$gte: 23}}, sort: {_id: -1}, update: {$set: {z: "z"}}}) 2016-11-11T14:09:57.261-0500 E QUERY [main] Error: findAndModifyFailed failed: { "ok" : 0, "errmsg" : "query for sharded findAndModify must have shardkey", "code" : 61, "codeName" : "ShardKeyNotFound" } : _getErrorWithCode@src/mongo/shell/utils.js:25:13 DBCollection.prototype.findAndModify@src/mongo/shell/collection.js:768:1 @(shell):1:1 mongos> db.foo.findAndModify({query: {_id: {$eq: 23}}, sort: {_id: -1}, update: {$set: {z: "z"}}}) { "_id" : 23, "x" : "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy", "y" : 0.8219226216897368 }
This is because we must be able to target the operation to a single shard.