Font size
WorksheetsISP610 MONGODB
Total questions: 20
Worksheet time: 13mins
Which of the following commands is used to show all databases in MongoDB?
db.showDatabases()
show dbs
show databases()
db.listDatabases()
Which MongoDB method is used to insert a single document into a collection?
db.collection.addOne()
db.collection.insert()
db.collection.insertOne()
db.collection.save()
Identify the syntax error:
db.users.insertOne({name: John, age: 30})
Missing semicolon
John must be in quotes
The entire document must be in quotes
No syntax error
To find all documents where status is "active", the correct query is:
db.users.find({status = "active"})
db.users.find(status: "active")
db.users.find({status: "active"})
db.users.select({status: "active"})
Which command deletes all documents from a collection named orders?
db.orders.drop()
db.orders.remove()
db.orders.truncate()
db.orders.deleteMany({})
Which aggregation stage is used to group documents by a specific field?
$match
$group
$project
$lookup
What will this command do?
db.students.updateMany({}, {$inc: {score: 5}})
Replace all documents with {score: 5}
Increase score by 5 for all students
Add a new field score with value 5 for one document
Error — $inc cannot be used in updateMany()
The _id field in MongoDB can be manually set during insertion.
TRUE
FALSE
Which of the following is the correct syntax to sort query results by age in descending order?
db.users.sort({age: desc})
db.users.find().orderBy(age, "desc")
db.users.find().sort({age: -1})
db.users.find({}).sort(age: -1)
Identify the error:
db.employees.find({salary: {$gte: 5000 $lte: 10000}})
No error
Use of wrong operator syntax
$gte must come after $lte
Missing comma between $gte and $lte
In an aggregation pipeline, which stage allows you to reshape or select specific fields from documents?
$match
$project
$group
$lookup
What does the following aggregation do?
db.sales.aggregate([ { $group: { _id: "$region", totalSales: { $sum: "$amount" } } } ])
Merges all documents into one total
Lists each sale individually
Filters only regions with totalSales > 0
Groups all documents by region and sums up their sales amounts
In MongoDB, the field that uniquely identifies each document is called (a) .
To join data from another collection inside an aggregation pipeline, we use the stage (a) .
To remove a field from a document using an update operation, you can use
{ $ (a) : { fieldName: "" } }.
In MongoDB, when related data is stored within the same document, it is called (a) .
When related data is stored in a separate collection and linked using an id or other field, it is called (a) .
Embedding data in MongoDB usually provides faster reads because all related data is in one document.
TRUE
FALSE
Referencing creates data duplication because the same information is stored in multiple documents.
TRUE
FALSE
Which of the following is an example of embedding in MongoDB?
Storing author information directly inside each book document
Creating an index on author_id
Storing all book details inside a books collection and linking with author_id
Joining books and authors collections using $lookup
