Learn MongoDB MCQs
Prepare MongoDB MCQs (Multiple choice Questions) for exam and job interviews.
What is the purpose of the `$addFields` stage in MongoDB aggregation?
1) To add new fields to documents
2) To remove fields from documents
3) To rename fields
4) To filter documents
Answer : Option 1
Which operator is used to perform a string comparison in MongoDB?
1) $regex
2) $match
3) $equals
4) $stringCompare
Answer : Option 1
What does the command `db.collection_name.updateMany({field: value}, {$set: {field2: newValue}})` do?
1) Updates field2 in all matching documents
2) Deletes all matching documents
3) Finds documents
4) Inserts new documents
Answer : Option 1
What is the default write concern in MongoDB?
1) 1
2) 0
3) majority
4) all
Answer : Option 1
Which command is used to check the current status of a replica set?
1) rs.status()
2) db.replicaSet.status()
3) show replica set
4) db.getStatus()
Answer : Option 1
What is the command to find documents with a specific field value in MongoDB?
1) db.collection_name.find({field: value})
2) db.collection_name.query({field: value})
3) db.collection_name.findByField(value)
4) db.collection_name.search({field: value})
Answer : Option 1
What does the command `db.collection_name.distinct(field)` return?
1) Distinct values of the specified field
2) Total count of documents
3) Documents matching the field
4) All values of the specified field
Answer : Option 1
Which operator is used to match documents with array elements in MongoDB?
1) $elemMatch
2) $arrayIncludes
3) $in
4) $arrayMatch
Answer : Option 1
What is the main purpose of the `db.collection_name.aggregate()` method?
1) To perform complex queries on collections
2) To find documents
3) To update documents
4) To delete documents
Answer : Option 1
Which command is used to count the number of documents in a collection?
1) db.collection_name.count()
2) db.collection_name.size()
3) db.collection_name.countDocuments()
4) db.collection_name.getCount()
Answer : Option 3