Learn MongoDB MCQs
Prepare MongoDB MCQs (Multiple choice Questions) for exam and job interviews.
What does the command `db.collection_name.drop()` do?
1) Deletes the entire collection
2) Removes specific documents
3) Clears all indexes
4) Drops a field
Answer : Option 1
Which operator is used to filter documents based on the date?
1) $date
2) $gt
3) $lt
4) $eq
Answer : Option 3
What is a MongoDB BSON?
1) Binary representation of JSON
2) A type of SQL
3) A form of data encryption
4) A query language
Answer : Option 1
What does the command `db.collection_name.find().sort({field: 1})` do?
1) Sorts the documents in ascending order
2) Sorts the documents in descending order
3) Filters the documents
4) Groups the documents
Answer : Option 1
Which command is used to create a user in MongoDB with specific roles?
1) db.createUser()
2) db.user.create()
3) db.addUser()
4) db.createAccount()
Answer : Option 1
What is the purpose of the `$unwind` stage in MongoDB aggregation?
1) Deconstructs an array field into separate documents
2) Filters documents
3) Groups documents
4) Sorts documents
Answer : Option 1
Which operator is used to check if a field value is greater than a specific value?
1) $gt
2) $lt
3) $eq
4) $gte
Answer : Option 1
What is the command to view the indexes of a collection?
1) db.collection_name.getIndexes()
2) db.collection_name.showIndexes()
3) db.collection_name.indexes()
4) db.collection_name.findIndexes()
Answer : Option 1
What is the primary function of the `$merge` stage in MongoDB aggregation?
1) Writes the results of aggregation to a collection
2) Combines two collections
3) Filters documents
4) Groups documents
Answer : Option 1
Which method is used to remove specific documents from a collection?
1) db.collection_name.deleteMany()
2) db.collection_name.remove()
3) db.collection_name.delete()
4) db.collection_name.removeMany()
Answer : Option 1