Details
-
Improvement
-
Resolution: Won't Do
-
Minor - P4
-
None
-
None
Description
https://docs.mongodb.com/manual/core/hashed-sharding/
I think it may be a good idea to clarify that hashed shard key field is required an immutable in the docs. Here is some sample output a user might encounter if they didn't realize this restriction.
output generated on 3.4.6:
mongos> sh.shardCollection("test.foo",{x:"hashed"})
|
{ "collectionsharded" : "test.foo", "ok" : 1 }
|
mongos> db.foo.insert({})
|
WriteResult({
|
"nInserted" : 0,
|
"writeError" : {
|
"code" : 61,
|
"errmsg" : "document { _id: ObjectId('5a29a6dd17fb6b18f562c0b8') } does not contain shard key for pattern { x: \"hashed\" }"
|
}
|
})
|
mongos> db.foo.insert({x:1})
|
WriteResult({ "nInserted" : 1 })
|
mongos> db.foo.update({x:1},{$unset: {x:1}})
|
WriteResult({
|
"nMatched" : 0,
|
"nUpserted" : 0,
|
"nModified" : 0,
|
"writeError" : {
|
"code" : 66,
|
"errmsg" : "After applying the update to the document with _id: ObjectId('5a29a6fb17fb6b18f562c0b9'), the 'x' (required and immutable) field was found to have been removed --{ _id: ObjectId('5a29a6fb17fb6b18f562c0b9'), x: 1.0 }"
|
}
|
})
|
mongos> db.foo.find()
|
{ "_id" : ObjectId("5a29a6fb17fb6b18f562c0b9"), "x" : 1 }
|
mongos> db.foo.update({x:1},{x:2})
|
WriteResult({
|
"nMatched" : 0,
|
"nUpserted" : 0,
|
"nModified" : 0,
|
"writeError" : {
|
"code" : 66,
|
"errmsg" : "After applying the update to the document {x: 1.0 , ...}, the (immutable) field 'x' was found to have been altered to x: 2.0"
|
}
|
})
|