Learn MongoDB MCQs

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

What does the command `db.collection_name.find({field: {$exists: true}})` do?

1) Finds documents where field exists

2) Finds documents where field is null

3) Finds documents where field is empty

4) Finds all documents

Answer : Option 1

Which operator is used for logical OR conditions in MongoDB?

1) $or

2) $and

3) $not

4) $nor

Answer : Option 1

What is the purpose of the `MongoDB Cloud` service?

1) Provides hosted MongoDB databases

2) Local MongoDB server

3) Data backup

4) Data analysis tool

Answer : Option 1

Which command is used to create a backup of the entire database in MongoDB?

1) mongodump

2) db.backup()

3) backup database_name

4) db.createBackup()

Answer : Option 1

What does the command `db.collection_name.find({field: {$in: [value1, value2]}})` do?

1) Finds documents where field matches any of the specified values

2) Finds documents where field matches all of the specified values

3) Finds documents where field does not match the specified values

4) Finds all documents

Answer : Option 1

Which operator is used to filter documents with specific array values in MongoDB?

1) $elemMatch

2) $in

3) $any

4) $arrayIncludes

Answer : Option 1

What is the command to restore a database from a backup in MongoDB?

1) mongorestore

2) db.restore()

3) restore database_name

4) db.database_name.recover()

Answer : Option 1

What is the main purpose of `MongoDB Atlas`?

1) Managed database service for MongoDB

2) Local MongoDB server

3) Data analysis tool

4) Backup service

Answer : Option 1

Which command is used to switch to a different database in MongoDB?

1) use database_name

2) db.switch(database_name)

3) db.change(database_name)

4) connect database_name

Answer : Option 1

What is the function of the `$lookup` stage in MongoDB aggregation?

1) Joins documents from different collections

2) Filters documents

3) Groups documents

4) Sorts documents

Answer : Option 1