Learn MongoDB MCQs
Prepare MongoDB MCQs (Multiple choice Questions) for exam and job interviews.
Which operator is used to merge two collections in MongoDB?
1) $merge
2) $join
3) $combine
4) $union
Answer : Option 1
Which command is used to create a user in MongoDB?
1) db.createUser()
2) db.user.create()
3) addUser()
4) db.createAccount()
Answer : Option 1
What is the purpose of the `$sort` stage in MongoDB aggregation?
1) To sort documents
2) To group documents
3) To filter documents
4) To limit documents
Answer : Option 1
Which method is used to check if a document exists in a collection?
1) db.collection_name.exists()
2) db.collection_name.find()
3) db.collection_name.findOne()
4) db.collection_name.search()
Answer : Option 3
What is the command to get the MongoDB version?
1) db.version()
2) mongo --version
3) db.getVersion()
4) mongo.version()
Answer : Option 1
Which of the following is a MongoDB cloud service?
1) MongoDB Atlas
2) MongoDB Cloud
3) MongoDB Online
4) MongoDB Web
Answer : Option 1
What does the command `db.collection_name.update({field: value}, {$set: {field2: newValue}})` do?
1) Updates field2 in documents matching the condition
2) Deletes field2 from documents
3) Finds documents
4) Inserts new documents
Answer : Option 1
Which method is used to remove all documents from a collection in MongoDB?
1) db.collection_name.deleteMany()
2) db.collection_name.removeAll()
3) db.collection_name.clear()
4) db.collection_name.drop()
Answer : Option 1
What does the command `db.collection_name.countDocuments()` return?
1) The count of documents in a collection
2) The total size of documents
3) The average size of documents
4) The list of document IDs
Answer : Option 1
Which operator is used to perform an AND condition in MongoDB?
1) $and
2) $or
3) $nor
4) $not
Answer : Option 1