Learn MongoDB MCQs

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

What is the command to view all databases in MongoDB?

1) SHOW DATABASES

2) db.showDatabases()

3) db.getDatabases()

4) LIST DATABASES

Answer : Option 1

Which command is used to create an index in MongoDB?

1) db.collection_name.createIndex()

2) db.createIndex()

3) db.collection_name.index()

4) db.collection_name.addIndex()

Answer : Option 1

What is the purpose of the MongoDB $match stage?

1) Filters documents

2) Joins collections

3) Projects fields

4) Sorts documents

Answer : Option 1

What does the MongoDB command `db.collection_name.find().sort()` do?

1) Sorts documents in a collection

2) Groups documents

3) Filters documents

4) Joins collections

Answer : Option 1

Which operator is used to check for the existence of a field in a document?

1) $exists

2) $has

3) $in

4) $exists()

Answer : Option 1

What is the primary purpose of MongoDB?

1) Document storage

2) Relational database management

3) File storage

4) Key-value storage

Answer : Option 1

Which of the following is a characteristic of MongoDB?

1) Schema-less

2) Fixed schema

3) ACID transactions

4) Multi-row transactions

Answer : Option 1

What is the command to drop a collection in MongoDB?

1) db.collection_name.drop()

2) DELETE collection_name

3) REMOVE collection_name

4) db.collection_name.delete()

Answer : Option 1

Which function retrieves a single document in MongoDB?

1) db.collection_name.find()

2) db.collection_name.findOne()

3) db.collection_name.getOne()

4) db.collection_name.get()

Answer : Option 2

What is the format of documents stored in MongoDB?

1) JSON

2) XML

3) CSV

4) YAML

Answer : Option 1