Sample questions
Question 1Easy
Which update operator changes the value of a field without replacing the entire document?
- $set
- $replace
- $put
- $change
Answer: A. $set
Explanation
$set updates only the named fields.
Step-by-step solution
- Use updateOne with filter.
- Second argument uses $set.
Why the other options are wrong
- B. $replace is not an update operator; it does not change one field.
- C. $put is not a MongoDB update operator.
- D. $change is not an update operator in MongoDB.
Question 2Easy
Which operator matches documents where a field equals any value in a given list?
- $all
- $or
- $in
- $eq
Answer: C. $in
Explanation
{field: {$in: [a, b, c]}} matches if the field equals any listed value.
Step-by-step solution
- Need membership in a list.
- $in does it.
Why the other options are wrong
- A. $all requires every listed value in an array field.
- B. $or combines whole conditions.
- D. $eq matches one value.
Question 3Easy
Which method returns all documents of the collection users?
- db.users.get()
- db.users.find()
- db.users.select()
- db.users.all()
Answer: B. db.users.find()
Explanation
find() with no filter matches every document.
Step-by-step solution
- find() returns all documents when no filter is used.
- db.users.find() is the correct syntax for this.
- Other options are not valid MongoDB methods.
- So, db.users.find() returns all documents of the collection users.
- The final answer is db.users.find().
Why the other options are wrong
- A. get is not a MongoDB collection method; reads use find().
- C. select is an SQL keyword, and MongoDB uses find() for reads.
- D. all is not a MongoDB shell method; find() with no filter returns every document.
Tip: Remember: find() with no arguments returns all documents in MongoDB.
Question 4Easy
Which method deletes the first document that matches a filter?
- removeAll()
- dropOne()
- clearOne()
- deleteOne()
Answer: D. deleteOne()
Explanation
deleteOne removes at most one matching document; deleteMany removes all matches.
Step-by-step solution
- MongoDB has deleteOne to remove the first document that matches a filter.
- DeleteMany removes all matches; deleteOne removes only one.
- So the answer is option D, deleteOne.
Why the other options are wrong
- A. RemoveAll is not a MongoDB method for a single match.
- B. DropOne is not a MongoDB method; drop removes a collection.
- C. ClearOne is not a MongoDB method.
Tip: DeleteOne removes one match; deleteMany removes all matches; drop removes a whole collection.
Question 5Medium
Which query finds documents where either age < 18 or age > 60?
- find({$or: [{age: {$lt: 18}}, {age: {$gt: 60}}]})
- find({age: {$lt: 18, $gt: 60}})
- find({age: {$lt: 18} || {$gt: 60}})
- find({$and: [{age: {$lt: 18}}, {age: {$gt: 60}}]})
Answer: A. find({$or: [{age: {$lt: 18}}, {age: {$gt: 60}}]})
Explanation
$or takes an array of conditions; any may match.
Step-by-step solution
- Two alternatives.
- Use $or.
Why the other options are wrong
- B. Both bounds in one object means AND, impossible here.
- C. || is not valid in a query document.
- D. $and would require both.
Question 6Medium
What does the following update do?
db.users.updateOne({name:'Ravi'}, {$inc: {score: 5}})
- Replaces score with the string '5' for every user whose name is Ravi in the collection
- Adds 5 to score of the first matching user (sets 5 if score is absent)
- Subtracts 5 from score
- Fails because $inc needs updateMany
Answer: B. Adds 5 to score of the first matching user (sets 5 if score is absent)
Explanation
$inc adds to a numeric field and creates it with that value if missing. updateOne touches only the first match.
Step-by-step solution
- Filter finds the first Ravi.
- $inc adds 5.
- Missing field starts at 0.
Why the other options are wrong
- A. updateOne only affects one document and $inc is numeric.
- C. Negative values subtract; 5 adds.
- D. $inc works with updateOne.
Question 7Medium
Which operator matches array documents containing all of the values 'a' and 'b' in the field tags?
- {tags: {$all: ['a','b']}}
- {tags: {$in: ['a','b']}}
- {tags: ['a','b']} for any order and extra elements
- {tags: {$size: 2}}
Answer: A. {tags: {$all: ['a','b']}}
Explanation
$all requires every listed value to be present, in any order and with extras allowed.
Step-by-step solution
- Both values must exist.
- $all.
Why the other options are wrong
- B. $in matches any one of the values, not all of them.
- C. A literal array needs an exact match in order.
- D. $size checks length only.
Question 8Medium
What is the difference between find({}) and findOne({})?
- findOne is faster because it always uses an index, while find scans everything
- find returns one document and findOne returns many
- findOne returns a single document or null; find returns a cursor
- They are identical
Answer: C. findOne returns a single document or null; find returns a cursor
Explanation
findOne gives the first matching document directly, while find gives a cursor that can iterate all matches.
Step-by-step solution
- Return types differ.
- Cursor vs single document.
Why the other options are wrong
- A. Speed is not the defining difference.
- B. find returns many documents; findOne returns only one.
- D. They differ: findOne returns one document, find returns a cursor.
Question 9Hard
Which document does {tags: {$all: ['a','b']}} match?
- {tags: ['a','c']}
- {tags: 'a'}
- {tags: ['b','c','a']}
- {tags: ['b']}
Answer: C. {tags: ['b','c','a']}
Explanation
$all requires the array to contain every listed element, in any order.
Step-by-step solution
- The query uses $all which means all elements must be present.
- ['a','b'] must be in the tags array.
- Option C has ['b','c','a'] which includes 'a' and 'b'.
- Other options miss at least one required element.
- Final answer: {tags: ['b','c','a']}.
Why the other options are wrong
- A. Element c is present but b is missing, so $all fails.
- B. A plain string is not an array with both a and b, so $all does not match it.
- D. Only b is present; a is missing, so $all needs both values.
Tip: Use $all to ensure all listed items are present in an array.
Question 10Hard
Given {_id:1, a:[1,2,3]}, what does db.c.find({a: {$gt: 2, $lt: 3}}) return?
- No documents, because no single element is both above 2 and below 3
- The document, because one element is >2 (3) and another is <3 (1 or 2)
- An error because two operators cannot share a field
- Only if a has exactly one element that satisfies both
Answer: B. The document, because one element is >2 (3) and another is <3 (1 or 2)
Explanation
Without $elemMatch, each condition may be satisfied by a different array element.
Step-by-step solution
- 3 > 2 satisfies $gt.
- 1 < 3 satisfies $lt.
- Different elements allowed.
Why the other options are wrong
- A. Cross-element matching makes it match.
- C. Two operators on one field are valid and do not throw an error.
- D. Array length not required.
Tip: Use $elemMatch to bind conditions to one element.
Practise all 35 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →