0
0
MongoDBquery~10 mins

Hash-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'
Ainventory
Bsales
Cusers
Dconfig
Attempts:
3 left
💡 Hint
Common Mistakes
Using a collection name instead of a database name.
Forgetting to put the database name in quotes.
2fill in blank
medium

Complete the code to shard the collection 'orders' in the 'sales' database using a hashed shard key on the field 'orderId'.

MongoDB
sh.shardCollection('sales.orders', { [1]: 'hashed' })
Drag options to blanks, or click blank then click option'
AcustomerId
Bstatus
Cdate
DorderId
Attempts:
3 left
💡 Hint
Common Mistakes
Using a field that is not the shard key.
Not specifying the shard key field correctly.
3fill in blank
hard

Fix the error in the code to shard the collection 'products' in the 'inventory' database using a hashed shard key on 'productId'.

MongoDB
sh.shardCollection('inventory.products', { [1]: 'hashed' })
Drag options to blanks, or click blank then click option'
Aproduct_id
BprodId
CproductId
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using a similar but incorrect field name.
Ignoring case sensitivity in field names.
4fill in blank
hard

Fill both blanks to create a hashed shard key on the 'customerId' field for the 'clients' collection in the 'crm' database.

MongoDB
sh.shardCollection('[1].clients', { [2]: 'hashed' })
Drag options to blanks, or click blank then click option'
Acrm
Borders
CcustomerId
Dclients
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping database and collection names.
Using the wrong field as shard key.
5fill in blank
hard

Fill all three blanks to enable sharding on the 'analytics' database, then shard the 'events' collection using a hashed shard key on 'eventId'.

MongoDB
sh.enableSharding('[1]');
sh.shardCollection('[2].[3]', { eventId: 'hashed' })
Drag options to blanks, or click blank then click option'
Aanalytics
Cevents
Dlogs
Attempts:
3 left
💡 Hint
Common Mistakes
Using different database names in enableSharding and shardCollection.
Using the wrong collection name.