MongoDB MCQs

Q.1 Which of the following best describes MongoDB’s approach to schemas?

A. Rigid and predefined
B. Flexible and dynamic
C. Fixed and unchangeable
D. None, as MongoDB does not use schemas

Shw me The Right Answer

Answer . B 

Q.2 In MongoDB, what is a ‘schema’?

A. A predefined structure for data
B. A query language for the database
C. A tool for data replication
D. A security feature

Shw me The Right Answer

Answer . A 

Q.3 Why might db.collection.insertOne({name: “Alice”, age: null}) not add a new document?

A. ‘age’ field cannot be null
B. ‘name’ field is duplicated
C. Collection does not exist
D. Missing required fields

Shw me The Right Answer

Answer . C 

Q.4 Spot the error in this command:
db.collection.deleteOne({ _id: 123 })

A. Incorrect method name
B. Incorrect field value
C. Missing quotation marks around the _id value
D. No error

Shw me The Right Answer

Answer . C 

Q.5 What’s wrong with this update command?
db.users.update({name: “John”}, {age: 30})

A. It replaces the entire document
B. It’s missing the $set operator
C. It updates all users named John
D. There’s no issue

Shw me The Right Answer

Answer . A 

Q.6 Identify the issue:
db.users.find({age: “25”})

A. Incorrect collection name
B. Incorrect field name
C. Type mismatch in query value
D. Missing query operator

Shw me The Right Answer

Answer . C 

Q.7 Which MongoDB command is used to add a new field to an existing document?

A. db.collection.update({}, {$set: {newField: value}})
B. db.collection.add({}, {newField: value})
C. db.collection.newField({newField: value})
D. db.collection.addField({newField: value})

Shw me The Right Answer

Answer . A 

Q.8 What does this command do?
db.products.find({price: {$gt: 100}})

A. Finds products with a price equal to 100
B. Finds products with a price less than 100
C. Finds products with a price greater than 100
D. Updates the price of products over 100

Shw me The Right Answer

Answer . C 

Q.9 Which command is used to update all documents that meet certain criteria in MongoDB?

A. db.collection.updateMany()
B. db.collection.updateOne()
C. db.collection.update()
D. db.collection.modify()

Shw me The Right Answer

Answer . A 

Q.10 What will the following command do?
db.users.remove({})

A. Remove all documents from the ‘users’ collection
B. Remove the ‘users’ collection
C. Remove one random document
D. Do nothing

Shw me The Right Answer

Answer . A 

You may also like...

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments