If you do an update with upsert on a sharded cluster, and the update document contains only update operators, but the '$set' update also includes the shard key, you get an error even if the key-value hasn't changed:
exec code_obj in self.user_global_ns, self.user_ns File "<ipython-input-50-74f5bdbf4070>", line 1, in <module> col.update({'symbol': document['symbol']}, {'$set': document}, w=1, upsert=True) File "/local/home/jblackburn/net/pymongo-2.4.1/pymongo/collection.py", line 481, in update check_keys, self.__uuid_subtype), safe) File "/local/home/jblackburn/net/pymongo-2.4.1/pymongo/mongo_client.py", line 852, in _send_message rv = self.__check_response_to_last_error(response) File "/local/home/jblackburn/net/pymongo-2.4.1/pymongo/mongo_client.py", line 795, in __check_response_to_last_error raise OperationFailure(details["err"], details["code"]) OperationFailure: Can't modify shard key's value. field: symbol: "random_symbol" collection: mongoose_jblackburn.centaur
The bad thing is that the code works fine on an unsharded collection, and only breaks when the collection is sharded - making it difficult to test.
- duplicates
-
SERVER-9074 Upsert fails with "cannot modify shard key" when not modifying shard key
- Closed