Learn MongoDB MCQs

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

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

1) Adds an item to an array

2) Removes an item from an array

3) Finds an item

4) Updates a field

Answer : Option 1

Which command is used to change the name of a collection?

1) db.collection_name.renameCollection()

2) db.collection_name.changeName()

3) db.renameCollection()

4) db.collection_name.updateName()

Answer : Option 1

How do you specify a condition in a MongoDB query?

1) db.collection_name.find({ field: value })

2) db.collection_name.find(field=value)

3) db.collection_name.search({ field=value })

4) db.collection_name.query({ field: value })

Answer : Option 1

Which MongoDB method can be used to count documents in a collection?

1) db.collection_name.count()

2) db.collection_name.total()

3) db.collection_name.sum()

4) db.collection_name.size()

Answer : Option 1

What is the command to connect to a MongoDB database from the shell?

1) mongo database_name

2) connect database_name

3) db.connect()

4) use database_name

Answer : Option 1

Which of the following commands is used to export data from MongoDB?

1) mongoexport

2) db.export()

3) exportData

4) dumpData

Answer : Option 1

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

1) Limits the number of documents returned

2) Filters documents

3) Sorts documents

4) Groups documents

Answer : Option 1

How do you perform a bulk write operation in MongoDB?

1) db.collection_name.bulkWrite()

2) db.collection_name.bulk()

3) db.collection_name.writeBulk()

4) db.collection_name.batchWrite()

Answer : Option 1

Which of the following is used to create a new document in MongoDB?

1) db.collection_name.insertOne()

2) db.collection_name.addDocument()

3) db.collection_name.create()

4) db.collection_name.insert()

Answer : Option 1

What is the purpose of the `$set` operator in MongoDB?

1) Updates the value of a field

2) Removes a field

3) Adds a field

4) Renames a field

Answer : Option 1