Learn MongoDB MCQs
Prepare MongoDB MCQs (Multiple choice Questions) for exam and job interviews.
What is the purpose of the `$out` stage in aggregation?
1) Writes the results to a specified collection
2) Joins two collections
3) Filters documents
4) Groups documents
Answer : Option 1
Which command is used to drop a collection?
1) db.collection_name.drop()
2) db.collection_name.remove()
3) db.deleteCollection()
4) db.collection_name.delete()
Answer : Option 1
What does the command `db.collection_name.find({field: {$not: {$gt: value}}})` do?
1) Finds documents where field is not greater than value
2) Finds documents where field is greater than value
3) Finds documents where field is null
4) Finds all documents
Answer : Option 1
What operator is used to filter documents with a specific substring in a string field?
1) $regex
2) $substring
3) $match
4) $contains
Answer : Option 1
Which command is used to remove all documents from a collection?
1) db.collection_name.deleteMany({})
2) db.collection_name.removeAll()
3) db.collection_name.clear()
4) db.collection_name.delete()
Answer : Option 1
What does the `db.collection_name.find().pretty()` command do?
1) Formats the output of documents for readability
2) Finds all documents
3) Finds documents matching a query
4) Deletes documents
Answer : Option 1
Which operator is used to filter documents with a specific value in an array?
1) $elemMatch
2) $in
3) $contains
4) $any
Answer : Option 1
What command is used to view the current database in use?
1) db
2) db.current()
3) db.getCurrentDatabase()
4) db.showCurrent()
Answer : Option 1
What does the command `db.collection_name.updateOne({field: value}, {$inc: {field2: 1}})` do?
1) Increments field2 by 1 in the first matching document
2) Updates field2 to 1 in the first matching document
3) Deletes the document
4) Inserts a new document
Answer : Option 1
Which command is used to create a new database in MongoDB?
1) use database_name
2) db.createDatabase("database_name")
3) db.newDatabase("database_name")
4) db.create("database_name")
Answer : Option 1