I'm using the following shard key
{"categoryId":1, "store":1, "_id":1}For testing purposes I only have one document in the collection:
mongos> db.offerChange.find() { "_id" : 123, "categoryId" : 9881, "store" : "NEW" }
When I want to update a field, I get correctly an alert "Can't modify shard key's value":
mongos> db.offerChange.update({"_id":123}, {$set:{"store":"NEWEST"}}, true, false) Can't modify shard key's value. field: store: "NEWEST" collection: offerChange.offerChange
However, I can modify the shard key by executing this:
mongos> db.offerChange.update({"_id":123}, {"_id":123, "categoryId":9881,"store":"NEWEST"}, true, false) mongos> db.offerChange.find() { "_id" : 123, "categoryId" : 9881, "store" : "NEWEST" } mongos>
Also, I could call save to change the shard key again (back):
mongos> db.offerChange.save({"categoryId":9881, "store":"NEW","_id":123}) mongos> db.offerChange.find() { "_id" : 123, "categoryId" : 9881, "store" : "NEW" } mongos>
Now, when I try to add a second shard key field to the query, I get the same but differently expressed correct alert:
mongos> db.offerChange.update({"_id":123,"store":"NEW"}, {"_id":123, "categoryId":9881,"store":"NEWEST"}, true, false) cannot modify shard key for collection offerChange.offerChange, found new value for store
However, when I replace the second by the third shard key field in the query, the update works again:
mongos> db.offerChange.update({"_id":123,"categoryId":9881}, {"_id":123, "categoryId":9881,"store":"NEWEST"}, true, false) mongos> db.offerChange.find() { "_id" : 123, "categoryId" : 9881, "store" : "NEWEST" }
I asked already in the mongoDB forum but nobody answered so far.
https://groups.google.com/group/mongodb-user/browse_thread/thread/300e0ff4676cb30b?hl=de&noredirect=true&pli=1
As I think that's rather a bug than a feature, I opened this bug report.
- depends on
-
SERVER-10161 Use new update framework to prevent changes to immutable fields (_id, sharding related, etc.)
- Closed
- is duplicated by
-
SERVER-8320 Inserting with a compound shard key results in data on wrong shard
- Closed
-
SERVER-8830 Able to modify component of shard key
- Closed
-
SERVER-8831 Able to unset embedded parts of the shard key -- changing it
- Closed
-
SERVER-10161 Use new update framework to prevent changes to immutable fields (_id, sharding related, etc.)
- Closed
- is related to
-
SERVER-5710 Update may result in doc without shard key
- Closed
-
SERVER-6835 Sharding edge case upserts documents with multiple _id attributes
- Closed
-
SERVER-9074 Upsert fails with "cannot modify shard key" when not modifying shard key
- Closed
-
SERVER-16978 sharding/SERVER-7379.js fails with a mixed version cluster
- Closed
- related to
-
SERVER-3940 Passing a complete document to update can break shard key immutability.
- Closed