Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
What is the main purpose of a single-field index in a NoSQL database?
Not quite. Try another option.
Answer: To speed up searches on one field
A single-field index helps the database find documents quickly when a query uses one indexed field.
Question 2 of 60 · Single Indexes · Easy
Which field could be indexed to quickly find a user by email address?
Not quite. Try another option.
Answer: email
An index on the email field can make searches for a specific email address faster.
Question 3 of 60 · Single Indexes · Easy
What is a possible disadvantage of creating many single-field indexes?
Not quite. Try another option.
Answer: Extra storage use
Indexes require storage space and may also increase the work needed when documents are inserted or updated.
Question 4 of 60 · Compound Indexes · Easy
What does a compound index contain?
Not quite. Try another option.
Answer: Multiple fields
A compound index is built from two or more fields and can support queries using those fields.
Question 5 of 60 · Compound Indexes · Easy
A compound index is created on category and price. Which query is most directly supported by its field order?
Not quite. Try another option.
Answer: Find products by category
The first field in a compound index can generally support queries that use that leading field.
Question 6 of 60 · Compound Indexes · Easy
Why does the order of fields matter in a compound index?
Not quite. Try another option.
Answer: Queries use the index prefix
The leading fields of a compound index form an index prefix that strongly affects which queries can use it.
Question 7 of 60 · Text Indexes · Easy
What is the primary purpose of a text index?
Not quite. Try another option.
Answer: To search words in text
A text index supports searches for words or phrases in text fields such as article titles and descriptions.
Question 8 of 60 · Text Indexes · Easy
Which type of field is most suitable for a text index?
Not quite. Try another option.
Answer: Article description
Text indexes are intended for word-based searches in text content.
Question 9 of 60 · Text Indexes · Easy
A text search for database is mainly intended to find documents containing what?
Not quite. Try another option.
Answer: The word database
Text search looks for matching terms in fields included in the text index.
Question 10 of 60 · Performance with Indexing · Easy
How can an appropriate index affect a read query?
Not quite. Try another option.
Answer: It can reduce documents examined
An index helps the database locate matching documents without scanning every document in the collection.
Question 11 of 60 · Performance with Indexing · Easy
What is a common cost of maintaining indexes during writes?
Not quite. Try another option.
Answer: Additional update work
When data changes, related index entries may also need to be updated.
Question 12 of 60 · Performance with Indexing · Easy
Which tool helps inspect how a database executes a query?
Not quite. Try another option.
Answer: explain()
The explain() method provides information about the query plan and execution statistics.
Question 13 of 60 · Covered Queries and explain() · Easy
What is a covered query?
Not quite. Try another option.
Answer: A query answered using only an index
A covered query can return the requested fields from the index without reading the full documents.
Question 14 of 60 · Covered Queries and explain() · Easy
Which condition is important for a query to be covered?
Not quite. Try another option.
Answer: Needed fields are in the index
The index must contain the fields used for filtering and the fields returned by the query.
Question 15 of 60 · Covered Queries and explain() · Easy
What can explain() show about a query?
Not quite. Try another option.
Answer: The selected query plan
explain() shows how the database plans and executes a query, including whether an index is used.
Question 16 of 60 · Aggregation Pipeline Concepts · Easy
What is an aggregation pipeline?
Not quite. Try another option.
Answer: A sequence of data-processing stages
An aggregation pipeline passes documents through stages that filter, group, sort, or transform data.
Question 17 of 60 · Aggregation Pipeline Concepts · Easy
Which aggregation stage filters documents?
Not quite. Try another option.
Answer: $match
The $match stage selects documents that satisfy specified conditions.
Question 18 of 60 · Aggregation Pipeline Concepts · Easy
Which aggregation stage groups documents by a field?
Not quite. Try another option.
Answer: $group
The $group stage combines documents according to a grouping expression and can calculate values such as totals.
Question 19 of 60 · Real-world Aggregation Examples · Easy
Which task is a suitable real-world use of aggregation?
Not quite. Try another option.
Answer: Calculate total sales by month
Aggregation is commonly used to summarize business data, such as calculating monthly sales totals.
Question 20 of 60 · Real-world Aggregation Examples · Easy
A store wants the average rating for each product. Which operation is needed?
Not quite. Try another option.
Answer: Group reviews and calculate averages
The reviews can be grouped by product, and an average accumulator can calculate each product's rating.
Question 21 of 60 · Single Indexes · Medium
A MongoDB collection named orders is frequently queried using { status: "pending" }. Which index most directly supports this query?
Not quite. Try another option.
Answer: db.orders.createIndex({ status: 1 })
A single-field ascending index on status allows MongoDB to locate pending orders without scanning the entire collection.
Question 22 of 60 · Single Indexes · Medium
A query filters products with { price: { $gte: 500 } } and sorts them using { price: -1 }. The collection has an index { price: 1 }. How can MongoDB use this index?
Not quite. Try another option.
Answer: It can scan the index in reverse order
MongoDB can traverse a single-field index in either direction, so { price: 1 } can support a descending sort on price.
Question 23 of 60 · Single Indexes · Medium
A users collection has a unique index on email. What happens when an application inserts a document whose email already exists?
Not quite. Try another option.
Answer: MongoDB rejects the insert with an error
A unique index prevents multiple documents from having the same indexed value, so the duplicate insert fails.
Question 24 of 60 · Compound Indexes · Medium
A collection has the compound index { customerId: 1, orderDate: -1 }. Which query can use both indexed fields most effectively?
The valid prefixes are department, department + salary, and all three fields. Skipping the leading field weakens index use.
Question 26 of 60 · Compound Indexes · Medium
An application commonly runs { region: "West", amount: { $gt: 1000 } } and sorts by { createdAt: -1 }. Which index best follows the equality-sort-range guideline?
Not quite. Try another option.
Answer: { region: 1, createdAt: -1, amount: 1 }
Placing the equality field first, the sort field second, and the range field last lets the index support filtering and sorting effectively.
Question 27 of 60 · Text Indexes · Medium
A collection has a text index on title and description. Which query searches both indexed fields for the terms wireless and charger?
MongoDB text searches use the $text query operator with a $search string across the fields in the text index.
Question 28 of 60 · Text Indexes · Medium
A text search returns several articles. Which projection adds each document's relevance score so the results can be sorted by relevance?
Not quite. Try another option.
Answer: { score: { $meta: "textScore" } }
The $meta: "textScore" expression exposes the relevance score produced by a $text search.
Question 29 of 60 · Text Indexes · Medium
A compound text index is defined as { category: 1, content: "text" }. What must a query include to use the text portion of this index?
Not quite. Try another option.
Answer: An equality condition on category
For a compound text index, query predicates must include equality matches on fields that appear before the text index key.
Question 30 of 60 · Performance with Indexing · Medium
After adding many indexes, read performance improves but write latency increases. What is the most likely cause?
Not quite. Try another option.
Answer: Each write must update several indexes
Inserts, updates, and deletes must maintain all affected indexes, so excessive indexing increases write work and storage use.
Question 31 of 60 · Performance with Indexing · Medium
A query uses an indexed active field, but almost every document has active: true. Why might the index provide little performance benefit for that value?
Not quite. Try another option.
Answer: The predicate has low selectivity
When a predicate matches most documents, MongoDB may examine many index entries and documents, reducing the index's advantage.
Question 32 of 60 · Performance with Indexing · Medium
A query examines 90,000 documents but returns only 20. Which change is most likely to improve its read efficiency?
Not quite. Try another option.
Answer: Create an index matching its filter pattern
A suitable index can reduce the number of documents examined relative to the small result set.
Question 33 of 60 · Covered Queries and explain() · Medium
A collection has an index { sku: 1, price: 1 }. Which query can be covered by this index, assuming sku and price are scalar fields?
Grouping by $courseId and applying $avg to $score calculates one average score for each course.
Question 39 of 60 · Real-world Aggregation Examples · Medium
An online store needs the three products with the highest total quantity sold. After unwinding items, which sequence should follow?
Not quite. Try another option.
Answer: $group by product, $sort descending, $limit to 3
The pipeline must total quantities per product before sorting those totals in descending order and keeping the top three.
Question 40 of 60 · Real-world Aggregation Examples · Medium
A sales dashboard needs monthly revenue from documents containing saleDate, quantity, and unitPrice. Which approach is appropriate?
Not quite. Try another option.
Answer: Group by sale year and month, then sum $multiply results
Monthly revenue is obtained by grouping on date parts and summing each sale's quantity multiplied by unitPrice.
Question 41 of 60 · Single Indexes · Hard
A collection has a single-field multikey index { tags: 1 }. For the query { tags: ["red", "blank"] }, which behavior is most accurate?
Not quite. Try another option.
Answer: The index finds candidates using the first array element, followed by document filtering.
For exact array equality, MongoDB can use the multikey index to find candidates containing the first element, but it must fetch documents to verify the entire array, including order.
Question 42 of 60 · Single Indexes · Hard
A unique single-field index is created on email. Some documents have email: null, while others omit email. What constraint does the index impose?
Not quite. Try another option.
Answer: It permits only one document whose indexed key resolves to null or missing.
A non-sparse unique single-field index stores a null key for both explicit null and missing values, so only one such document is permitted.
Question 43 of 60 · Single Indexes · Hard
An index is created as { email: 1 } with partialFilterExpression: { active: true }. Which query is eligible to use the complete partial index without risking omitted matching documents?
Not quite. Try another option.
Answer: { active: true, email: "a@example.com" }
A query can use a partial index only when its predicate implies the partial filter. Explicitly requiring active: true satisfies that condition.
Question 44 of 60 · Compound Indexes · Hard
A query filters by tenantId = 7, restricts createdAt to a range, and sorts by rating descending. Which compound index best follows the ESR guideline while avoiding a blocking sort?
Not quite. Try another option.
Answer: { tenantId: 1, rating: -1, createdAt: 1 }
ESR places equality fields first, sort fields next, and range fields last. This ordering supports the tenant predicate and rating sort before applying the date range.
Question 45 of 60 · Compound Indexes · Hard
Given the compound index { a: 1, b: -1, c: 1 } and no filtering predicate, which sort can be satisfied by scanning the entire index in reverse?
Not quite. Try another option.
Answer: { a: -1, b: 1, c: -1 }
A compound index supports its declared sort pattern and the complete reverse pattern. Every direction must be reversed together.
Question 46 of 60 · Compound Indexes · Hard
A compound index { tags: 1, ratings: 1 } is required, and both fields may contain arrays. Under which condition can MongoDB maintain this compound multikey index?
Not quite. Try another option.
Answer: No indexed document may contain arrays in both fields simultaneously.
A compound multikey index may have different array-indexed fields across documents, but no single indexed document may contain arrays for more than one indexed field.
Question 47 of 60 · Text Indexes · Hard
A compound text index is defined as { tenantId: 1, body: "text" }. Which predicate is required for efficient use of this index in a text search?
Not quite. Try another option.
Answer: An equality predicate on tenantId together with the $text predicate
For a compound text index, queries must provide equality conditions for all ordinary index fields that precede the text key.
Question 48 of 60 · Text Indexes · Hard
Which query correctly returns documents matching database indexing and orders them by MongoDB text relevance?
Text relevance is exposed through the $meta: "textScore" expression, which can be projected and used as the sort specification.
Question 49 of 60 · Text Indexes · Hard
Documents contain a lang field that identifies the language used by each document's indexed text. Which text-index configuration enables per-document stemming and stop-word rules?
Not quite. Try another option.
Answer: Set language_override to lang when creating the index.
The language_override option names a document field whose value selects the language used for stemming and stop-word processing.
Question 50 of 60 · Performance with Indexing · Hard
A write-heavy collection has ten overlapping indexes, while read latency is already acceptable. What is the most likely effect of adding another index?
Not quite. Try another option.
Answer: Higher write amplification, storage use, and cache pressure
Each relevant index must be maintained during writes. Additional indexes also consume disk and compete for memory, potentially reducing overall throughput.
Question 51 of 60 · Performance with Indexing · Hard
A collection has an index { active: 1 }, but { active: true } matches approximately 48% of ten million documents. Why might the optimizer prefer a collection scan?
Not quite. Try another option.
Answer: The index has low selectivity, so scanning keys and fetching many documents may cost more.
An index is not automatically faster. For a low-selectivity predicate, index traversal plus many random document fetches can be more expensive than a sequential collection scan.
Question 52 of 60 · Covered Queries and explain() · Hard
Given the index { tenantId: 1, status: 1, total: 1 }, which query and projection can be fully covered by that index?
A multikey index can cover a query when the projected fields exclude the array field and the query does not use $elemMatch in a way that requires document inspection.
Question 54 of 60 · Covered Queries and explain() · Hard
For a query filtering { tenant: 42, status: "open" }, sorting by { createdAt: -1 }, and limiting to 20, explain("executionStats") shows an IXSCAN on { status: 1 }, totalKeysExamined: 500000, totalDocsExamined: 500000, and nReturned: 20. Which index is the strongest improvement?
Not quite. Try another option.
Answer: { tenant: 1, status: 1, createdAt: -1 }
The existing scan is weakly selective and examines far too many records. Equality fields followed by the sort field let MongoDB target the tenant and status while producing results in the requested order.
Question 55 of 60 · Aggregation Pipeline Concepts · Hard
Consider a pipeline where $addFields computes discounted, followed by $match: { region: "EU", discounted: { $lt: 100 } }. Which optimization is semantically valid?
Not quite. Try another option.
Answer: Move the region predicate before $addFields while leaving the discounted predicate after it.
The independent region condition can be pushed earlier, potentially enabling index use. The discounted condition must remain after the stage that creates that field.
Question 56 of 60 · Aggregation Pipeline Concepts · Hard
Four documents have items values ['a','b'], [], missing, and 'x', respectively. How many output documents result from $unwind with preserveNullAndEmptyArrays: true?
Not quite. Try another option.
Answer: Five output documents
The two-element array produces two outputs; the empty and missing values each produce one preserved output; and the scalar value is treated as a single element. Thus .
Question 57 of 60 · Aggregation Pipeline Concepts · Hard
A correlated $lookup compares foreign stock_item with a local item and foreign instock with local ordered using $expr. When can a foreign compound index { stock_item: 1, instock: 1 } support both comparisons?
Not quite. Try another option.
Answer: When each local variable resolves to a scalar constant for the foreign subquery and the index is not multikey
Indexable $expr comparisons in $lookup must compare foreign fields with values treated as constants for each local input. Missing values and multikey indexes limit this optimization.
Question 58 of 60 · Real-world Aggregation Examples · Hard
Each paid order contains lineItems, where every item has productId, quantity, and unitPrice. Which stage sequence correctly calculates revenue per product?
Not quite. Try another option.
Answer: $match paid orders, $unwind line items, then group by product and sum quantity times price
Filtering first reduces work, unwinding creates one record per line item, and grouping with $sum: { $multiply: ["$lineItems.quantity", "$lineItems.unitPrice"] } computes product revenue.
Question 59 of 60 · Real-world Aggregation Examples · Hard
A telemetry collection stores multiple status records per device. Which pipeline pattern reliably returns the most recent complete record for every deviceId?
Not quite. Try another option.
Answer: Sort by deviceId ascending and timestamp descending, then group by device using $first
Sorting places the newest record first within each device group. $group can then retain the first document, commonly through $first: "$$ROOT".
Question 60 of 60 · Real-world Aggregation Examples · Hard
An API must return one page of filtered results and the total number of matching documents from the same aggregation input. Which pipeline design is most appropriate?
Not quite. Try another option.
Answer: Apply common filtering, then use $facet with a paginated data branch and a separate count branch.
$facet sends the same matched input to independent subpipelines. One branch can sort, skip, and limit, while another uses $count without being affected by pagination.
That's unit 4
Answer a few questions and your score shows up here.
Nearly through. Did unit 4 of CSE494 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 4 of CSE494 save you a night before the exam?
Then you can help keep it free for the next batch. 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.