Learn MongoDB MCQs
Prepare MongoDB MCQs (Multiple choice Questions) for exam and job interviews.
What is the primary purpose of the `$project` stage in aggregation?
1) To specify which fields to include or exclude
2) To filter documents
3) To sort documents
4) To group documents
Answer : Option 1
Which command is used to view the structure of a document in a collection?
1) db.collection_name.findOne()
2) db.collection_name.schema()
3) db.collection_name.structure()
4) db.collection_name.getStructure()
Answer : Option 1
What is a primary key in MongoDB?
1) The unique identifier for a document
2) The main database
3) A type of index
4) A query operator
Answer : Option 1
What does the command `db.collection_name.find().limit(n)` do?
1) Limits the number of documents returned to n
2) Returns all documents
3) Finds documents matching a condition
4) Sorts the documents
Answer : Option 1
Which method is used to close a connection to MongoDB?
1) db.close()
2) mongo.close()
3) connection.close()
4) db.connection.close()
Answer : Option 1
What is the role of a MongoDB client?
1) To connect to and interact with the database
2) To store data
3) To manage collections
4) To create indexes
Answer : Option 1
Which command is used to create a new collection in MongoDB?
1) db.createCollection()
2) db.collection_name.create()
3) db.addCollection()
4) db.collection_name.new()
Answer : Option 1
What is the purpose of the `$addFields` stage in MongoDB aggregation?
1) To add new fields to documents
2) To remove fields
3) To update fields
4) To filter documents
Answer : Option 1
Which operator is used to match documents with a specific field?
1) $eq
2) $match
3) $field
4) $find
Answer : Option 1
Which command is used to insert a document into a collection?
1) db.collection_name.insertOne()
2) db.collection_name.add()
3) db.collection_name.create()
4) db.collection_name.insert()
Answer : Option 1