[DOCS-9306] findAndModify query must contain an exact match Created: 11/Nov/16  Updated: 30/Oct/23  Resolved: 17/Mar/23

Status: Closed
Project: Documentation
Component/s: Server
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Task Priority: Minor - P4
Reporter: Charlie Swanson Assignee: Andrew Aldridge
Resolution: Won't Do Votes: 0
Labels: bite-sized
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:
Days since reply: 46 weeks, 6 days ago
Story Points: 0.25

 Description   

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.



 Comments   
Comment by Sarah Olson [ 17/Mar/23 ]

Closing this out on the grounds that:

  • Details of this request are significantly outdated. 
  • Our documentation has evolved substantially since this request was made. 

Based on this, closing as WON'T DO. Please don't hesitate to give me a shout or to reopen if you disagree.

Generated at Thu Feb 08 07:58:03 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.