Loading

Quipoin Menu

Learn • Practice • Grow

mongodb / Update Operations
mcq
Direction: Choose the correct option

Q1.

Which method updates a single document that matches a filter?
A. db.collection.updateMany()
B. db.collection.replaceOne()
C. db.collection.update()
D. db.collection.updateOne()
Direction: Choose the correct option

Q2.

What is the purpose of the `$set` operator in an update operation?
A. To rename a field
B. To increment a numeric field
C. To set the value of a field
D. To remove a field
Direction: Choose the correct option

Q3.

How would you increment the 'views' field by 1 for a specific document?
A. {$mul: {views: 1}}
B. {$inc: {views: 1}}
C. {$add: {views: 1}}
D. {$set: {views: 'views+1'}}
Direction: Choose the correct option

Q4.

What does `db.users.updateMany({}, {$set: {active: true}})` do?
A. Creates a new field only for the first document
B. Updates one user document
C. Sets the 'active' field to true for all user documents
D. Throws an error
Direction: Choose the correct option

Q5.

Which operator is used to add an element to an array field?
A. $insert
B. $add
C. $addToSet
D. $push