[SERVER-18331] Remove justOne, with sharding, fails when specifying a comparison query operator Created: 05/May/15  Updated: 09/Jul/16  Resolved: 05/May/15

Status: Closed
Project: Core Server
Component/s: Querying, Sharding
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Jonathan Abrahams Assignee: Unassigned
Resolution: Done Votes: 0
Labels: 32qa
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to DOCS-5356 Sharding with remove/update specifyin... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

var st = new ShardingTest({name: "singleNode", shards: 1, chunksize: 1});
st.s.adminCommand({enableSharding: "test"});
st.s.getDB("test").abc.ensureIndex({a: 1});
st.s.adminCommand({shardCollection: "test.abc", key: {a: 1}});
for (var i=0; i<10; i++) {
    st.s.getDB("test").abc.insert({a: i});
}
st.s.getDB("test").abc.remove({a: {$eq: 6}},{justOne: true});
st.s.getDB("test").abc.remove({a: 9}, {justOne: true});
st.s.getDB("test").abc.remove({a: {$gte: 6}},{justOne: true});
st.stop();

Participants:

 Description   

To remove a document in a sharded collection, using the justOne option, the shard key is required. This works for the equality operator. Specify a comparison operator and it fails, i.e., $gte, $lt, with the following error:

WriteResult({
	"nRemoved" : 0,
	"writeError" : {
		"code" : 61,
		"errmsg" : "delete { q: { a: { $gte: 6.0 } }, limit: 1 } does not contain _id or shard key for pattern { a: 1.0 }"
	}
})



 Comments   
Comment by Jonathan Abrahams [ 05/May/15 ]

Perhaps the documentation and error message both require improvement, if theses type of queries are not supported in a sharded environment. The documentation is unclear what is meant by "must include the shard key or the _id field in the query specification". The error message and documentation should be more precise in defining the type of queries for the justOne options.

Comment by Scott Hernandez (Inactive) [ 05/May/15 ]

How is this a bug?

The query does not contain a concrete shard key (as you specify a range of possible shard key values) nor the _id of the document, as stated in the error message. Here are the docs about this behavior: http://docs.mongodb.org/manual/reference/limits/#Single-Document-Modification-Operations-in-Sharded-Collections

Are you just suggesting the error message should be better, or documentation should be improved?

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