-
Type: Bug
-
Resolution: Works as Designed
-
Priority: Major - P3
-
Affects Version/s: 1.1.9
-
Component/s: Shell API
-
2
-
Iteration Yonkers, Iteration Zanzibar, Iteration Cuttlefish, Iteration Dolphin
-
Needed
-
Hi Team,
I was testing the sh.shardCollection method in the New MongoDB Shell and realized that it appears to incorrectly parse the arguments when the "options" document is included. Here's an example:
mlaunch init --sharded 2 --replicaset --csrs db.getSiblingDB("test").createCollection("mongosh", { collation: { locale: "en", strength: 2 } } ) db.getSiblingDB("test").getCollection("mongosh").createIndex( { a: 1 }, { collation: { locale: "simple" } } ) sh.enableSharding("test") sh.shardCollection("test.mongosh", { a: 1 }, { collation: { locale: "simple" } } )
This results in the collection being sharded with the unique property set to "false":
'test.mongosh': { shardKey: { a: 1 }, unique: false, balancing: true,
On the contrary, if you use the Legacy MongoDB Shell you receive the following error when executing the sh.shardCollection command in the same way:
mlaunch init --sharded 2 --replicaset --csrs db.getSiblingDB("test").createCollection("mongo", { collation: { locale: "en", strength: 2 } } ) db.getSiblingDB("test").getCollection("mongo").createIndex( { a: 1 }, { collation: { locale: "simple" } } ) sh.enableSharding("test") sh.shardCollection("test.mongo", { a: 1 }, { collation: { locale: "simple" } } ) { "ok" : 0, "errmsg" : "Collection has default collation: collation: { locale: \"en\", caseLevel: false, caseFirst: \"off\", strength: 2, numericOrdering: false, alternate: \"non-ignorable\", maxVariable: \"punct\", normalization: false, backwards: false, version: \"57.1\" }. Must specify collation {locale: 'simple'}", "code" : 2, "codeName" : "BadValue", "operationTime" : Timestamp(1644510736, 4), "$clusterTime" : { "clusterTime" : Timestamp(1644510736, 4), "signature" : { "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="), "keyId" : NumberLong(0) } } }
Based on sh.shardCollection, the Legacy MongoDB Shell behavior is the right one and the New MongoDB Shell should be fixed:
If specifying the options document, you must explicitly specify the value for unique.
Would you please review this?
Regards
Diego