Learn MongoDB MCQs

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

Which operator is used to perform a bitwise OR operation in MongoDB?

1) $bit

2) $or

3) $and

4) $not

Answer : Option 1

What is the command to enable sharding on a MongoDB database?

1) sh.enableSharding()

2) db.shardDatabase()

3) enableSharding()

4) db.setupSharding()

Answer : Option 1

Which method is used to retrieve a specific document by ID?

1) db.collection_name.findOne({_id: id})

2) db.collection_name.getById(id)

3) db.collection_name.find({_id: id})

4) db.collection_name.getById()

Answer : Option 1

What does the command `db.collection_name.aggregate([{$group: {_id: "$field"}}])` do?

1) Groups documents by the specified field

2) Finds all documents

3) Filters documents

4) Sorts documents

Answer : Option 1

Which command is used to display all collections in a database?

1) show collections

2) db.getCollections()

3) db.collection_name.list()

4) db.getAllCollections()

Answer : Option 1

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

1) Writes the results to a specified collection

2) Combines two collections

3) Filters documents

4) Groups documents

Answer : Option 1

Which operator is used to find documents that do not match a specified condition?

1) $not

2) $or

3) $and

4) $nor

Answer : Option 1

What does the command `db.collection_name.updateOne({field: value}, {$set: {field2: newValue}})` do?

1) Updates field2 in the first matching document

2) Updates all matching documents

3) Deletes the document

4) Inserts a new document

Answer : Option 1

What is the command to create an index on multiple fields in MongoDB?

1) db.collection_name.createIndex({field1: 1, field2: 1})

2) db.collection_name.index({field1: 1, field2: 1})

3) db.collection_name.createMultiIndex()

4) db.collection_name.addIndex({field1: 1, field2: 1})

Answer : Option 1

What does the command `db.collection_name.dropIndex("index_name")` do?

1) Drops the specified index from the collection

2) Removes a field from documents

3) Deletes all documents

4) Renames the index

Answer : Option 1