Learn MongoDB MCQs
Prepare MongoDB MCQs (Multiple choice Questions) for exam and job interviews.
Which command is used to view the current database in MongoDB?
1) db.currentDatabase()
2) db.getCurrentDatabase()
3) db.database()
4) db.getName()
Answer : Option 1
What is a MongoDB replica set?
1) A group of MongoDB servers that maintain the same data set
2) A backup of the database
3) A sharded cluster
4) A database with multiple collections
Answer : Option 1
What is the purpose of the `$unset` operator in MongoDB?
1) Removes a field from a document
2) Updates a field
3) Adds a new field
4) Renames a field
Answer : Option 1
Which operator is used to perform a conditional update in MongoDB?
1) $cond
2) $if
3) $case
4) $when
Answer : Option 1
What command is used to start the MongoDB shell?
1) mongo
2) start mongo
3) run mongo
4) connect mongo
Answer : Option 1
What is the purpose of the `$merge` stage in MongoDB aggregation?
1) Combines documents into a new collection
2) Filters documents
3) Groups documents
4) Sorts documents
Answer : Option 1
Which of the following is used to limit the number of fields returned in a MongoDB query?
1) db.collection_name.find({}, { field1: 1, field2: 1 })
2) db.collection_name.find({}, { field1, field2 })
3) db.collection_name.find({ field1, field2 })
4) db.collection_name.select({ field1: 1, field2: 1 })
Answer : Option 1
What is the command to show all collections in the current database?
1) show collections
2) db.getCollections()
3) db.listCollections()
4) db.showCollections()
Answer : Option 1
Which command is used to create a database in MongoDB?
1) use database_name
2) create database_name
3) db.createDatabase()
4) new database_name
Answer : Option 1
What does the `$lookup` stage do in MongoDB?
1) Performs a left outer join
2) Filters documents
3) Groups documents
4) Sorts documents
Answer : Option 1