mongos> use bad
switched to db bad
mongos> sh.shardCollection("bad.coll1", { "age": "hashed" })
{ "code" : 26, "ok" : 0, "errmsg" : "database bad not found" }
mongos> sh.enableSharding("bad")
{ "ok" : 1 }
mongos> sh.shardCollection("bad.coll1", { "age": "hashed" })
{ "collectionsharded" : "bad.coll1", "ok" : 1 }
mongos> db.coll1.insert({_id : 1, "name" : "a", "age" : 10})
WriteResult({ "nInserted" : 1 })
mongos> db.coll1.update({_id: 1}, {_id : 1, "name" : "a", "age" : 11}, {upsert: true})
WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : 1 })
mongos> db.coll1.find()
{ "_id" : 1, "name" : "a", "age" : 11 }
{ "_id" : 1, "name" : "a", "age" : 10 }
mongos> db.coll1.update({_id: 1}, {_id : 1, "name" : "a", "age" : 11}, {upsert: true})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 0 })
mongos> db.coll1.update({_id: 1}, {_id : 1, "name" : "a", "age" : 12}, {upsert: true})
WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : 1 })
mongos> db.coll1.update({_id: 1}, {_id : 1, "name" : "a", "age" : 13}, {upsert: true})
WriteResult({
"nMatched" : 0,
"nUpserted" : 0,
"nModified" : 0,
"writeError" : {
"code" : 66,
"errmsg" : "After applying the update to the document {age: 10.0 , ...}, the (immutable) field 'age' was found to have been altered to age: 13.0"
}
})
mongos>
mongos> version()
3.4.14
mongos> db.coll1.find()
{ "_id" : 1, "name" : "a", "age" : 12 }
{ "_id" : 1, "name" : "a", "age" : 11 }
{ "_id" : 1, "name" : "a", "age" : 10 }