0
0
MongoDBquery~10 mins

Horizontal scaling mental model 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 specify the shard key for horizontal scaling in MongoDB.

MongoDB
sh.shardCollection("mydb.mycollection", { [1]: 1 })
Drag options to blanks, or click blank then click option'
AuserId
Bdatabase
Ctimestamp
Dlocation
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a field that is not present in all documents
Using a field with low cardinality
2fill in blank
medium

Complete the code to add a new shard to the MongoDB cluster.

MongoDB
sh.addShard("[1]")
Drag options to blanks, or click blank then click option'
Amongos:27017
Badmin:27017
Cconfigsvr:27019
Dshard0001/mongo1:27017
Attempts:
3 left
💡 Hint
Common Mistakes
Using mongos or config server address instead of shard address
3fill in blank
hard

Fix the error in the command to enable sharding on a database.

MongoDB
sh.enableSharding("[1]")
Drag options to blanks, or click blank then click option'
Aadmin
Bmydb
Cconfig
Dlocal
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to shard system databases like admin or config
4fill in blank
hard

Fill both blanks to create a shard key with a compound index for better data distribution.

MongoDB
sh.shardCollection("mydb.orders", { [1]: 1, [2]: 1 })
Drag options to blanks, or click blank then click option'
AcustomerId
BorderDate
Cstatus
Dregion
Attempts:
3 left
💡 Hint
Common Mistakes
Using unrelated fields that don't help distribute data evenly
5fill in blank
hard

Fill all three blanks to configure a MongoDB sharded cluster with a config server, shard, and mongos router.

MongoDB
config = new Mongo("[1]")
sh.addShard("[2]")
mongos = new Mongo("[3]")
Drag options to blanks, or click blank then click option'
Aconfigsvr1:27019
Bshard0002/mongo2:27017
Cmongos1:27017
Dadmin:27017
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up ports or using admin database address