0
0
MongoDBquery~10 mins

Range-based sharding in MongoDB - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable sharding on the database named 'sales'.

MongoDB
sh.enableSharding("[1]")
Drag options to blanks, or click blank then click option'
Ausers
Binventory
Csales
Dorders
Attempts:
3 left
💡 Hint
Common Mistakes
Using a collection name instead of the database name.
Misspelling the database name.
2fill in blank
medium

Complete the code to shard the 'orders' collection on the 'orderDate' field.

MongoDB
sh.shardCollection("sales.[1]", { orderDate: 1 })
Drag options to blanks, or click blank then click option'
Acustomers
Borders
Cproducts
Dinventory
Attempts:
3 left
💡 Hint
Common Mistakes
Using the database name instead of the collection name.
Forgetting to specify the shard key field.
3fill in blank
hard

Fix the error in the code to create a range shard on the 'age' field for the 'users' collection.

MongoDB
sh.splitAt("users.users", { age: [1] })
Drag options to blanks, or click blank then click option'
A25
B"25"
C{25}
D[25]
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the number, making it a string.
Using brackets or braces which are invalid here.
4fill in blank
hard

Fill both blanks to split the 'orders' collection at the specified range and move the chunk to shard02.

MongoDB
sh.splitAt("sales.orders", { [1]: 1000 })
sh.moveChunk("sales.orders", { [2]: 1000 }, "shard02")
Drag options to blanks, or click blank then click option'
AorderId
BcustomerId
CorderDate
Dstatus
Attempts:
3 left
💡 Hint
Common Mistakes
Using different fields for splitting and moving chunks.
Using a field that is not the shard key.
5fill in blank
hard

Fill all three blanks to create a range-based shard key on 'price', split at 500, and move the chunk to 'shard01'.

MongoDB
sh.shardCollection("store.products", { [1]: 1 })
sh.splitAt("store.products", { [2]: [3] })
sh.moveChunk("store.products", { [2]: [3] }, "shard01")
Drag options to blanks, or click blank then click option'
Aprice
C500
D1000
Attempts:
3 left
💡 Hint
Common Mistakes
Using different fields for shard key and split/move commands.
Using the wrong split value.