0
0
MongoDBquery~10 mins

Bulk write operations 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 initialize an unordered bulk operation on the 'users' collection.

MongoDB
const bulk = db.collection('users').[1]();
Drag options to blanks, or click blank then click option'
AstartBulk
BinitializeUnorderedBulkOp
CbulkWrite
DcreateBulkOp
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'bulkWrite' which is a different method for bulk operations.
Using non-existent methods like 'startBulk' or 'createBulkOp'.
2fill in blank
medium

Complete the code to add an insert operation for a document with name 'Alice' to the bulk operation.

MongoDB
bulk.[1]({ name: 'Alice' });
Drag options to blanks, or click blank then click option'
AupdateOne
BinsertOne
Cinsert
DaddInsert
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'insertOne' which is used outside bulk operations.
Using 'updateOne' which is for updates, not inserts.
3fill in blank
hard

Fix the error in the code to update a document where name is 'Bob' by setting age to 30 in the bulk operation.

MongoDB
bulk.find({ name: 'Bob' }).updateOne({ [1]: { age: 30 } });
Drag options to blanks, or click blank then click option'
A$set
B$update
Cupdate
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the dollar sign in the operator name.
Using 'update' which is not a valid update operator.
4fill in blank
hard

Fill both blanks to add a delete operation for documents where status is 'inactive' and then execute the bulk operation.

MongoDB
bulk.find({ status: 'inactive' }).[1]();
const result = bulk.[2]();
Drag options to blanks, or click blank then click option'
AdeleteMany
Bexecute
Cremove
Drun
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'deleteMany' which is not a method in legacy bulk operations.
Using 'run' instead of 'execute' to run the bulk.
5fill in blank
hard

Fill all three blanks to add an update operation that increments 'score' by 5 for a document where 'level' is 10, then add an insert for a new user, and finally execute the bulk operation.

MongoDB
bulk.find({ level: 10 }).[1]({ [2]: { score: 5 } });
bulk.[3]({ name: 'Charlie', level: 1 });
const res = bulk.execute();
Drag options to blanks, or click blank then click option'
AupdateOne
B$inc
Cinsert
DupdateMany
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'updateMany' instead of 'updateOne' when only one document should be updated.
Using '$set' instead of '$inc' to increment a value.
Using 'insertOne' which is not used in bulk operations.