|
This limitation also appears to affect $in:
mongos> db.c.update({a: {$in: [1, 5]}}, {$inc: {foo: 1}})
|
WriteResult({
|
"nMatched" : 0,
|
"nUpserted" : 0,
|
"nModified" : 0,
|
"writeError" : {
|
"code" : 61,
|
"errmsg" : "A single update on a sharded collection must contain an exact match on _id (and have the collection default collation) or contain the shard key (and have the simple collation). Update request: { q: { a: { $in: [ 1.0, 5.0 ] } }, u: { $inc: { foo: 1.0 } }, multi: false, upsert: false }, shard key pattern: { a: 1.0 }"
|
}
|
})
|
Furthermore, the findAndModify command is affected in addition to update, for both the $or and $in cases:
mongos> db.c.findAndModify({query: {a: {$or: [{a: 1}, {a: 5}]}}, update: {$inc: {foo: 1}}})
|
2018-04-19T18:08:50.574-0400 E QUERY [js] Error: findAndModifyFailed failed: {
|
"ok" : 0,
|
"errmsg" : "unknown operator: $or",
|
"code" : 2,
|
"codeName" : "BadValue",
|
"$clusterTime" : {
|
"clusterTime" : Timestamp(1524175727, 3),
|
"signature" : {
|
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
|
"keyId" : NumberLong(0)
|
}
|
},
|
"operationTime" : Timestamp(1524175727, 3)
|
} :
|
mongos> db.c.findAndModify({query: {a: {$in: [1, 5]}}, update: {$inc: {foo: 1}}})
|
2018-04-19T18:07:11.325-0400 E QUERY [js] Error: findAndModifyFailed failed: {
|
"ok" : 0,
|
"errmsg" : "Query for sharded findAndModify must contain the shard key",
|
"code" : 61,
|
"codeName" : "ShardKeyNotFound",
|
"$clusterTime" : {
|
"clusterTime" : Timestamp(1524175627, 1),
|
"signature" : {
|
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
|
"keyId" : NumberLong(0)
|
}
|
},
|
"operationTime" : Timestamp(1524175627, 1)
|
} :
|
|