Learn MongoDB MCQs
Prepare MongoDB MCQs (Multiple choice Questions) for exam and job interviews.
What is the command to check the status of a MongoDB replica set?
1) rs.status()
2) db.replSet.status()
3) db.replicaSet()
4) rs.getStatus()
Answer : Option 1
What is the purpose of the `MongoDB Shell`?
1) To interact with the database via command line
2) To create backups
3) To visualize data
4) To manage users
Answer : Option 1
Which command is used to delete a specific document by ID?
1) db.collection_name.deleteOne({_id: id})
2) db.collection_name.removeById(id)
3) db.collection_name.delete(id)
4) db.collection_name.remove({_id: id})
Answer : Option 1
What is the function of the `$match` stage in aggregation?
1) Filters documents
2) Sorts documents
3) Groups documents
4) Projects fields
Answer : Option 1
What does the command `db.collection_name.find({field: {$gt: value}})` do?
1) Finds documents where field is greater than value
2) Finds documents where field is less than value
3) Finds documents where field equals value
4) Finds documents where field is null
Answer : Option 1
Which command is used to rename a collection?
1) db.collection_name.renameCollection("new_name")
2) db.renameCollection()
3) db.collection_name.updateName()
4) db.collection_name.setName()
Answer : Option 1
What is the purpose of the `$group` stage in aggregation?
1) Groups documents by specified criteria
2) Filters documents
3) Joins collections
4) Sorts documents
Answer : Option 1
Which command is used to create a user with specific roles?
1) db.createUser()
2) db.user.create()
3) db.addUser()
4) db.createAccount()
Answer : Option 1
What is a primary key in MongoDB?
1) Unique identifier for documents
2) Type of index
3) Field in SQL
4) Database name
Answer : Option 1
Which command displays the indexes of a collection?
1) db.collection_name.getIndexes()
2) db.collection_name.indexes()
3) db.showIndexes()
4) db.collection_name.listIndexes()
Answer : Option 1