Unit 2: MongoDB Basics and CRUD Operations - Practice Quiz
1 What does a MongoDB database primarily contain?
2 Which MongoDB shell command displays the name of the currently selected database?
show dbs
db
list databases with all configuration details
db.current()
3 What is a collection in MongoDB?
4 A MongoDB collection is most similar to which concept in a relational database?
5 How is data organized inside a MongoDB document?
6 Which field is automatically used as the unique identifier of a MongoDB document?
primary_identifier_value
_id
_key
id_
7 Which operation adds a single document to a MongoDB collection?
insertOne()
findOne()
createOneDocumentAndAutomaticallyBuildEveryPossibleIndex()
updateOne()
8 Which method is commonly used to retrieve documents from a MongoDB collection?
replaceCollection()
drop()
find()
insertMany()
9 What does BSON stand for?
10 Which BSON data type stores a true or false value?
11
Which BSON data type is commonly generated for the _id field by MongoDB?
12 Which BSON data type should be used to store a list of values in one field?
13
Which MongoDB shell command selects a database named school?
use school
open school
db.createCollection("school")
select school
14 When is a newly selected MongoDB database normally created permanently?
use is entered
15
Which command creates a collection named students explicitly?
db.createCollection("students")
db.newCollection("students")
db.students.createDatabase()
create students
16 Which command removes the currently selected MongoDB database?
db.drop()
db.dropDatabase()
db.removeEveryCollectionBeforeClosingTheDatabase()
db.deleteDatabase()
17
Which command removes a collection named students?
db.students.remove()
db.students.deleteAllDocumentsAndRetainTheCollection()
db.dropDatabase()
db.students.drop()
18 What is embedding in MongoDB data modeling?
19 What is a reference in MongoDB data modeling?
20 What is the main purpose of an index in MongoDB?
21
A developer runs use inventory in mongosh, but inventory does not appear in show dbs. What action will make the database appear?
db.createDatabase() once
22
Which command explicitly creates an orders collection with a JSON Schema validator?
db.createCollection("orders", { validator: schema })
db.orders.create({ validator: schema })
db.orders.insertCollection({ validator: schema })
db.createDatabase("orders", { validator: schema })
23
An administrator has selected the test_archive database and wants to permanently remove that database. Which command should be executed?
db.dropAllCollections()
db.deleteDatabase()
db.dropDatabase()
db.drop()
24
A collection must reject documents whose quantity field is not an integer. Which MongoDB feature is most appropriate?
25
Given { customer: { address: { city: "Pune" } } }, which filter correctly finds documents where the nested city is Pune?
{ "customer.address.city": "Pune" }
{ "customer->address->city": "Pune" }
{ customer: "address.city.Pune" }
{ customer[address][city]: "Pune" }
26
A document contains scores: [{ subject: "Math", mark: 72 }, { subject: "Science", mark: 91 }]. Which filter requires subject: "Math" and mark: { $gt: 80 } to match the same array element?
{ "scores.subject": "Math", "scores.mark": { $gt: 80 } }
{ scores: { $all: ["Math", 80] } }
{ scores: { subject: "Math", mark: { $gt: 80 } } }
{ scores: { $elemMatch: { subject: "Math", mark: { $gt: 80 } } } }
27
Which update increments an existing stock value by 5 without replacing the rest of the document?
db.items.updateOne({ sku: "A1" }, { stock: 5 })
db.items.updateOne({ sku: "A1" }, { $push: { stock: 5 } })
db.items.updateOne({ sku: "A1" }, { $inc: { stock: 5 } })
db.items.updateOne({ sku: "A1" }, { $set: { stock: 5 } })
28
A financial application must store 19.99 without typical binary floating-point rounding. Which BSON value is most appropriate?
NumberInt("19.99")
NumberDecimal("19.99")
NumberLong("19.99")
Double("19.99")
29 A query must compare event times chronologically and use a date index efficiently. How should new event times normally be stored?
30
A collection uses MongoDB's default _id values. Which statement about an ObjectId is correct?
31
A field can contain either an integer or a numeric string. Which query selects only documents where rating is stored as a string?
{ rating: { $cast: "string" } }
{ rating: { $format: "string" } }
{ rating: { $type: "string" } }
{ rating: { $value: "string" } }
32 An order's line items are always displayed with the order, are limited in number, and should remain as they were when purchased. Which model is most suitable?
33 Millions of comments belong to articles, and comments are frequently paginated and updated independently. Which modeling choice is most appropriate?
34 A user's shipping address and profile settings must be updated atomically in a single operation. Which design best supports this requirement?
35
A frequent query is find({ status: "PAID" }).sort({ createdAt: -1 }). Which index best supports both filtering and sorting?
{ createdAt: -1, status: 1 }
{ status: -1, createdAt: 1 }
{ createdAt: 1, status: -1 }
{ status: 1, createdAt: -1 }
36
Given a compound index { category: 1, price: 1, rating: -1 }, which query uses the index's longest valid prefix?
find({ price: { $lt: 30 }, rating: 5 })
find({ rating: 5, price: { $lt: 30 } })
find({ rating: 5 })
find({ category: "Book", price: { $lt: 30 } })
37
An index { email: 1, name: 1 } exists. Which query can be covered by this index without fetching documents, assuming _id is not needed?
find({ email: "a@x.com" }, { name: 1, _id: 0 })
find({ email: "a@x.com" }, { address: 1, _id: 0 })
find({ name: "Ana" }, { address: 1, _id: 0 })
find({ address: "Pune" }, { email: 1, _id: 0 })
38 A query is unexpectedly slow. Which command provides actual execution statistics such as examined keys and examined documents?
db.orders.find(query).inspect("allPlans")
db.orders.find(query).analyze("queryPlanner")
db.orders.find(query).explain("executionStats")
db.orders.find(query).profile("executionStats")
39
A collection has an index on the array field tags. What type of index does MongoDB automatically create for that field?
40
Only active accounts are frequently queried by email, while inactive accounts should not consume index space. Which index is most appropriate?
db.accounts.createIndex({ email: 1 }, { sparse: false })
db.accounts.createIndex({ email: 1 }, { unique: false })
db.accounts.createIndex({ email: 1 }, { expireAfterSeconds: 0 })
db.accounts.createIndex({ email: 1 }, { partialFilterExpression: { active: true } })
41
An administrator runs use telemetry in mongosh, then immediately checks show dbs. The telemetry database is absent. Which explanation is correct?
show dbs excludes every database that does not contain at least one user-defined index.
use creates the database only after the shell is restarted and reconnects to the same server.
show dbs reads a cached catalog that is refreshed only after a replica-set election.
use selects a database handle, but the database is materialized only after data or a collection is created.
42
A script connects with db currently set to staging and executes db.dropDatabase(). It then inserts into db.events without issuing another use command. What is the expected result?
staging and implicitly creates the events collection.
events, while staging remains absent from the catalog.
test because the current database was dropped.
43 A collection has a JSON Schema validator and two secondary indexes. It is dropped and then recreated by inserting its first document. Which state should be expected?
44
Given documents {_id: 1, x: null}, {_id: 2}, and {_id: 3, x: 0}, which query matches only the document where x explicitly has the BSON null value?
{x: {$ne: null}}
{x: null}
{x: {$exists: false}}
{x: {$type: 10}}
45
A financial application must store 0.1 and perform server-side arithmetic without binary floating-point approximation. Which BSON type is most appropriate?
string, because aggregation arithmetic converts strings without precision loss
Decimal128, because it represents decimal fractions with decimal semantics
double, because MongoDB normalizes decimal literals before storing them
int64, because MongoDB automatically preserves the decimal scale
46
Two clients insert the same instant using BSON Date values, one from UTC and one from a +05:30 local time converted correctly by its driver. How are these values stored?
47
Why is sorting by a default ObjectId _id only an approximation of sorting by exact creation time?
48
A document contains items: [{sku: "A", qty: 2}, {sku: "B", qty: 20}]. Which query requires sku: "A" and qty: {$gt: 10} to be satisfied by the same array element?
{"items.sku": "A", "items.qty": {$gt: 10}}
{items: {$all: [{sku: "A"}, {qty: {$gt: 10}}]}}
{items: {$elemMatch: {sku: "A", qty: {$gt: 10}}}}
{items: {$in: [{sku: "A", qty: {$gt: 10}}]}}
49
A collection contains {_id: 7, status: "open", total: 40}. What happens when replaceOne({_id: 7}, {_id: 8, status: "closed"}) attempts to replace it?
_id: 7 to _id: 8.
status while preserving both _id: 7 and total.
_id: 7 and removes total.
_id value would be changed.
50 An order must preserve the product name and unit price exactly as they were at purchase time, even after the product catalog changes. Which model best supports this requirement?
51 A sensor document appends one reading every second to an embedded array and is retained indefinitely. Which redesign most directly addresses the principal scaling risk?
52 Users can belong to millions of groups, and groups can contain millions of users. Memberships are frequently added and removed, and queries run in both directions. Which primary model is most robust?
53
A frequent query is find({tenantId: 42, createdAt: {$gte: start}}).sort({score: -1}). Which compound index most closely follows the equality-sort-range guideline?
{createdAt: 1, tenantId: 1, score: -1}
{score: -1, createdAt: 1, tenantId: 1}
{tenantId: 1, score: -1, createdAt: 1}
{tenantId: 1, createdAt: 1, score: -1}
54
For an index {a: 1, b: -1}, which sort can use the index order directly when there is no filter?
{b: -1, a: 1}
{a: -1, b: -1}
{a: -1, b: 1}
{a: 1, b: 1}
55
A document has both tags: ["red", "sale"] and ratings: [4, 5]. Why can creating the compound index {tags: 1, ratings: 1} fail?
56
With index {tenantId: 1, email: 1}, which query and projection can be covered by that index, assuming no relevant collation or multikey complication?
find({tenantId: 9}, {email: 1})
find({tenantId: 9}, {email: 1, _id: 0})
find({tenantId: 9}, {email: 1, name: 1, _id: 0})
find({tenantId: 9}, {name: 1, _id: 0})
57
A partial index is created as {email: 1} with partialFilterExpression: {active: true}. Which query is eligible to use it without a hint?
find({email: "a@example.com", active: true})
find({email: "a@example.com", active: {$ne: false}})
find({email: "a@example.com"})
find({email: "a@example.com", active: {$exists: true}})
58
An index on {name: 1} was created with a case-insensitive English collation. A query filters by name but specifies the default simple collation. What is the key optimization consequence?
59
Given a standard ascending index on {username: 1}, which predicate is most likely to produce a bounded index scan?
{username: {$regex: /^son/}}
{username: {$regex: /son$/}}
{username: {$regex: /^son/i}}
{username: {$regex: /son/}}
60
An explain("executionStats") result shows totalKeysExamined: 200000, totalDocsExamined: 12, and nReturned: 12. What is the strongest conclusion?
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →