0
0
MongoDBquery~10 mins

Schema design for write-heavy workloads 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 insert a new document into the collection.

MongoDB
db.collection.[1]({ name: "Alice", age: 30 })
Drag options to blanks, or click blank then click option'
AinsertOne
BfindOne
CupdateOne
DdeleteOne
Attempts:
3 left
💡 Hint
Common Mistakes
Using findOne instead of insertOne will only retrieve data.
updateOne requires an existing document to update.
deleteOne removes documents, not adds.
2fill in blank
medium

Complete the code to create an index that improves write performance by avoiding duplicates.

MongoDB
db.collection.createIndex({ email: 1 }, { [1]: true })
Drag options to blanks, or click blank then click option'
Asparse
Bbackground
Cunique
DexpireAfterSeconds
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sparse' does not enforce uniqueness.
Background indexing affects build time, not uniqueness.
expireAfterSeconds is for TTL indexes, unrelated here.
3fill in blank
hard

Fix the error in the update operation to increment the 'count' field by 1.

MongoDB
db.collection.updateOne({ _id: 1 }, { [1]: { count: 1 } })
Drag options to blanks, or click blank then click option'
A$inc
B$addToSet
C$push
D$set
Attempts:
3 left
💡 Hint
Common Mistakes
Using $set replaces the value instead of incrementing.
$push and $addToSet are for arrays, not numbers.
4fill in blank
hard

Fill both blanks to create a schema design that embeds comments inside posts for faster writes.

MongoDB
const commentSchema = new Schema({ text: String, date: [2] }); const postSchema = new Schema({ title: String, comments: [[1]] });
Drag options to blanks, or click blank then click option'
AcommentSchema
BDate
CString
DNumber
Attempts:
3 left
💡 Hint
Common Mistakes
Using String instead of commentSchema for comments loses structure.
Using Number for date is not appropriate.
5fill in blank
hard

Fill all three blanks to write a bulk insert operation for multiple user documents.

MongoDB
db.users.[1]([{ name: "John" }, { name: "Jane" }], { [2]: true, [3]: 1000 })
Drag options to blanks, or click blank then click option'
AinsertMany
Bordered
Cw
Dupsert
Attempts:
3 left
💡 Hint
Common Mistakes
Using insertOne inserts only one document.
Upsert is for update operations, not inserts.