Learn MongoDB MCQs

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

Which command is used to enable a replica set in MongoDB?

1) rs.initiate()

2) enableReplicaSet()

3) startReplicaSet()

4) db.enableReplicaSet()

Answer : Option 1

What is the primary purpose of MongoDB Atlas?

1) Cloud-based MongoDB database

2) Local MongoDB server

3) MongoDB client

4) MongoDB command line

Answer : Option 1

Which method is used to retrieve the first document in a collection?

1) db.collection_name.findOne()

2) db.collection_name.first()

3) db.collection_name.getFirst()

4) db.collection_name.find()

Answer : Option 1

What does the `$geoWithin` operator do in MongoDB?

1) Finds documents within a specified geometry

2) Finds documents outside a specified geometry

3) Sorts documents

4) Aggregates data

Answer : Option 1

Which command is used to compact a collection in MongoDB?

1) db.collection_name.repair()

2) db.collection_name.compact()

3) db.collection_name.defrag()

4) db.collection_name.optimize()

Answer : Option 1

What is the purpose of the `MongoDB Compass`?

1) GUI for MongoDB

2) Command line interface for MongoDB

3) Database backup tool

4) Data analysis tool

Answer : Option 1

Which operator is used to perform a conditional operation in MongoDB?

1) $cond

2) $if

3) $switch

4) $case

Answer : Option 1

What does the `db.collection_name.find().skip(n)` method do?

1) Skips the first n documents

2) Returns n documents

3) Filters documents

4) Sorts documents

Answer : Option 1

Which command is used to show the status of a replica set?

1) rs.status()

2) db.getReplicaSetStatus()

3) show replica set

4) db.replicaset.status()

Answer : Option 1

What is a MongoDB cursor?

1) An object that allows iteration over the result set

2) A method to query documents

3) A way to filter documents

4) A command to create indexes

Answer : Option 1