What does: "Can't modify shard key's value fieldid for collection: foo.foo" mean in MongoDB-Perl? What does: "Can't modify shard key's value fieldid for collection: foo.foo" mean in MongoDB-Perl? mongodb mongodb

What does: "Can't modify shard key's value fieldid for collection: foo.foo" mean in MongoDB-Perl?


Two things :

  1. Shard keys are immutable. Once you set them they cannot be updated. This makes sense because it would result in data having to be moved from one shard to another. So, update that include fields that are (or are part of) the shard key will fail with the error you're getting. The first two error messages are both the same error.

  2. You cannot make inserts into a sharded collection without the shard key. Again, this makes sense from mongo's point of view. If you're not providing a shard key how will it know to which shard it should route the insert? An upsert operation should therefore include the shard key in the find "criteria" (so, the first parameter in update(criteria, update, upsert, multi)) but not the "update" since that's the only correct way to get the shard key in an upserted document without having it in the "update" parameter which, as you noticed, is not allowed.

Make sense?


I think the answer to this question is that there is a bug in mongodb 2.0. Check this jira issue:

https://jira.mongodb.org/browse/SERVER-3657