Complete the code to enable sharding on the database named 'sales'.
sh.enableSharding("[1]")
The enableSharding command activates sharding on the specified database. Here, the database is named 'sales'.
Complete the code to shard the 'orders' collection on the 'orderDate' field.
sh.shardCollection("sales.[1]", { orderDate: 1 })
The shardCollection command shards the specified collection. Here, the collection is 'orders' in the 'sales' database.
Fix the error in the code to create a range shard on the 'age' field for the 'users' collection.
sh.splitAt("users.users", { age: [1] })
The splitAt command requires the shard key value as a number, not as a string or object. So, use 25 without quotes or brackets.
Fill both blanks to split the 'orders' collection at the specified range and move the chunk to shard02.
sh.splitAt("sales.orders", { [1]: 1000 }) sh.moveChunk("sales.orders", { [2]: 1000 }, "shard02")
Both splitAt and moveChunk commands use the shard key field, which is 'orderId' here, to specify the range and chunk location.
Fill all three blanks to create a range-based shard key on 'price', split at 500, and move the chunk to 'shard01'.
sh.shardCollection("store.products", { [1]: 1 }) sh.splitAt("store.products", { [2]: [3] }) sh.moveChunk("store.products", { [2]: [3] }, "shard01")
The shard key is 'price'. The split and move chunk commands use the same field 'price' and split at the value 500.