Unit 5: MongoDB Integration - Practice Quiz
1 What is Mongoose in a Node.js application?
2 Which object is commonly used to define the structure of documents in Mongoose?
3 Which method is commonly used to connect Mongoose to MongoDB?
4 What does a Mongoose model represent?
5 What is PyMongo?
6 Which PyMongo class is commonly used to create a connection to MongoDB?
7 In PyMongo, what does a collection store?
8 Which PyMongo method retrieves a single document?
9 What does the letter C represent in CRUD?
10 Which CRUD operation is used to retrieve documents from MongoDB?
11 Which MongoDB method inserts one document into a collection?
12 Which MongoDB method updates one matching document?
13 Which MongoDB method removes one matching document?
14 What is predictive analytics used for?
15 How can MongoDB support predictive analytics?
16 Which type of data can MongoDB store for an AI prediction system?
17 What is a common purpose of using AI with MongoDB data?
18 What is the main goal of query optimization?
19 What can an index help MongoDB do?
20 What may AI analyze to recommend better database queries?
21 A Mongoose application only needs to read user records and return plain JSON objects. The records will not be modified or saved. Which query is most appropriate for reducing Mongoose document-processing overhead?
User.find({ active: true }).populate()
User.find({ active: true }).hydrate()
User.find({ active: true }).validate()
User.find({ active: true }).lean()
22
A developer updates a product with Product.findByIdAndUpdate(id, update). The returned value contains the product data from before the update. Which option should be added to return the updated document?
{ strict: true }
{ new: true }
{ upsert: true }
{ lean: true }
23
A Mongoose schema requires price to be at least 1. An update using findOneAndUpdate() incorrectly accepts price: 0. Which option should be included in the update operation?
{ minimize: true }
{ autoIndex: true }
{ runValidators: true }
{ timestamps: true }
24 An order-creation endpoint must insert an order and decrease product stock as one atomic operation. What is the most appropriate Mongoose approach?
25
A Flask route receives a MongoDB document ID as a URL string. Which conversion is normally required before using it in a PyMongo _id query?
ObjectId(id_string)
bytes(id_string)
UUID(id_string)
str(id_string)
26
A Python service must retrieve only the name and score fields while excluding _id. Which PyMongo query uses the correct projection?
find({}, {"name": 0, "score": 0, "_id": 1})
find({"_id": 0}, {"name": 1, "score": 1})
find({}, {"name": 1, "score": 1, "_id": 0})
find({"name": 1, "score": 1}, {"_id": 0})
27
A PyMongo application frequently creates a new MongoClient for every request and closes it immediately afterward. What is the preferred design for a typical web service?
MongoClient for each collection operation
MongoClient across requests
MongoClient for each returned document
28 A data-loading job has 5,000 independent update operations to send through PyMongo. Which approach generally reduces network round trips while allowing the operations to be grouped?
find_one() before every update
aggregate() with output projections
watch() with update filters
bulk_write() with update models
29 An inventory API must reduce stock by 1 only when the current stock is greater than 0. Which update best prevents two concurrent requests from overselling the final item?
$set: { stock: 0 }
$inc: { stock: -1 }
$set: { stock: stock - 1 }
stock: { $gt: 0 } and apply $inc: { stock: -1 }
30
A REST API calls delete_one({"_id": id}) and receives deleted_count == 0. Which HTTP response is most appropriate when the identifier was valid but no matching resource existed?
409 Conflict
404 Not Found
201 Created
304 Not Modified
31
A profile update endpoint receives only { "city": "Pune" }. The existing name and email fields must remain unchanged. Which update document should the application construct?
{ "$set": { "city": "Pune" } }
{ "$replaceWith": { "city": "Pune" } }
{ "$unset": { "city": "Pune" } }
{ "$rename": { "city": "Pune" } }
32
Two users can edit the same document. The document contains a numeric version field. How should the application implement optimistic concurrency control?
_id and a new version, then decrement version
version only, then replace every field in the document
_id and the expected version, then increment version
_id only, then reset version to its initial value
33 A predictive-maintenance model needs each machine's average temperature during the previous hour. Where can this feature be efficiently computed before model inference?
34 A model predicts whether a customer will cancel a subscription tomorrow. Which feature would cause target leakage during training?
35
An application stores model predictions with modelVersion, predictedAt, and featuresVersion. What is the main analytical benefit of storing this metadata?
36 A deployed fraud model should score new transactions shortly after they are inserted into MongoDB. Which MongoDB capability is most suitable for triggering this near-real-time workflow?
37
An AI optimizer observes the frequent query find({ tenantId: T, status: S }).sort({ createdAt: -1 }). Which compound index is the strongest candidate?
{ tenantId: 1, status: 1, createdAt: -1 }
{ createdAt: -1, tenantId: 1, status: 1 }
{ tenantId: -1, createdAt: 1, status: -1 }
{ status: 1, createdAt: 1, tenantId: -1 }
38
After an AI system recommends an index, which explain() evidence most strongly indicates that the query became more efficient?
39 An optimizer proposes indexes for every observed query pattern, but the collection has heavy write traffic. Which factor should prevent automatic acceptance of all recommendations?
40 Query traffic changes substantially between business hours and overnight batch processing. What input would best help an AI optimizer adapt its recommendations?
41
A Mongoose schema defines email with unique: true. Two concurrent requests create documents with the same email, and both validations pass before either write completes. What is the reliable way to enforce uniqueness?
required: true on the email field
save()
findOne() before every insert
42
A Mongoose update uses Model.updateOne({ _id: id }, { $set: payload }), where payload is received from an API client. Which design best prevents unauthorized field changes and operator injection?
$set after checking authentication
strict: false so Mongoose preserves client fields
$
43
A service uses findOneAndUpdate() to increment an account balance and expects the returned document to contain the new balance. Which configuration is required for that expectation?
new: true
timestamps: false
lean: true
overwrite: true
44
A Mongoose query uses populate('customer') and returns thousands of orders. The customer documents contain large profile fields that the API never exposes. Which change most directly reduces response size and hydration cost?
populate() with estimatedDocumentCount()
strictPopulate to false
populate('customer') twice
populate('customer', 'name tier')
45 A PyMongo application must transfer a newly inserted document's identifier to another collection, and both writes must commit atomically. Which approach is appropriate when the deployment supports transactions?
with_transaction()
insert_many() on unrelated collections
acknowledged=False for lower latency
46 A PyMongo worker retries a transaction after a transient network error. The transaction inserts a document with a client-generated UUID and a unique index on that UUID. Why is this design useful?
47
A PyMongo query sorts by event_time descending and limits results, but performance degrades as the collection grows. The filter is { "tenant_id": t, "status": "open" }. Which index is generally the strongest candidate?
{ tenant_id: 1, status: 1, event_time: -1 }
{ status: 1, event_time: -1 }
{ event_time: -1 }
{ tenant_id: 1, event_time: -1 }
48
A Python API reads documents using find() and converts them to JSON. Some documents contain ObjectId and timezone-aware datetime values. What is the most robust boundary design?
49
An order update must change status from pending to paid only if it is still pending, and the application must know whether the transition occurred. Which operation is most suitable?
_id and status: "pending", then inspect matched_count
_id only and inspect the modified document
50
An application performs pagination with skip(page * 100).limit(100) on a collection receiving continuous inserts. Which issue is most likely, and what is the better strategy for a large collection?
51
A delete endpoint receives a user-supplied filter and passes it directly to deleteMany(). Which control is most important for preventing accidental broad deletion?
deleteMany() instead of deleteOne()
52 A bulk import contains 10,000 independent records. Some records violate a unique index, but valid records should still be inserted. Which behavior best matches this requirement?
replaceOne() without an upsert option
53 A read-modify-write workflow increments a counter, but concurrent requests occasionally overwrite each other's increments. Which database-side change is the best fix?
$inc in a single atomic update
54
A predictive model estimates customer churn from historical customer snapshots. The feature pipeline includes each customer's last_support_ticket, but the ticket may have been created after the prediction timestamp. What problem does this create?
55 A feature-generation aggregation joins transactions to accounts and then groups by account. The transaction collection is much larger, and only transactions from the previous 30 days are relevant. Where should the time filter normally be applied?
$match before the join
56 A production model uses a feature that is computed from documents arriving through a change stream. Events can arrive out of order. Which design best preserves correct time-window features?
57 A team evaluates a fraud model by randomly splitting transactions into training and test sets. Fraud patterns evolve over time, and the model will score future transactions. Which evaluation design is more defensible?
58
An optimizer recommends an index { status: 1, region: 1 } for a workload, but the query filters on region and sorts by created_at while omitting status. Why may the recommendation be ineffective?
59 An AI query tuner reports that a query's average latency improved after adding an index, but p99 latency and write throughput both worsened. What is the best conclusion?
60 A learned optimizer detects that a query is slow because a predicate has highly skewed values. It proposes different plans for frequent and rare values. What capability is this exploiting?
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 →