Learn MongoDB MCQs

Prepare MongoDB MCQs (Multiple choice Questions) for exam and job interviews.

Which command is used to find documents with a specific condition in MongoDB?

1) db.collection_name.find({ condition })

2) db.collection_name.get({ condition })

3) db.collection_name.search({ condition })

4) db.collection_name.retrieve({ condition })

Answer : Option 1

What is the command to create a new index in MongoDB?

1) db.collection_name.createIndex({ field: 1 })

2) db.createIndex({ field: 1 })

3) db.collection_name.index({ field: 1 })

4) db.collection_name.addIndex({ field: 1 })

Answer : Option 1

What is the command to check the status of a MongoDB server?

1) db.serverStatus()

2) db.getStatus()

3) mongo.status()

4) db.status()

Answer : Option 1

Which method is used to find all documents in a collection?

1) db.collection_name.find()

2) db.collection_name.getAll()

3) db.collection_name.selectAll()

4) db.collection_name.retrieveAll()

Answer : Option 1

What is the purpose of the `$addFields` stage in MongoDB aggregation?

1) Adds new fields to documents

2) Filters documents

3) Groups documents

4) Sorts documents

Answer : Option 1

Which operator is used to perform an OR condition in MongoDB?

1) $or

2) $and

3) $not

4) $nor

Answer : Option 1

What command is used to exit the MongoDB shell?

1) exit

2) quit

3) close

4) leave

Answer : Option 1

What command is used to update multiple documents in MongoDB?

1) db.collection_name.updateMany()

2) db.collection_name.update()

3) db.collection_name.updateAll()

4) db.collection_name.modify()

Answer : Option 1

Which MongoDB operator is used to check if an array contains a specified value?

1) $in

2) $contains

3) $exists

4) $arrayContains

Answer : Option 1

What is the main purpose of the MongoDB `$project` stage?

1) To specify the fields to include or exclude

2) To sort documents

3) To group documents

4) To filter documents

Answer : Option 1