Grokking MongoDB
0% completed
Create an Index
Ask MongoDB how it answered a query for one product, and it reports that it read every document in the collection to find one:
db.products.find({ name: "Banana" }).explain("executionStats")
// Output, trimmed winningPlan: { stage: 'COLLSCAN', filter: { name: { '$eq': 'Banana' } }, direction: 'forward' } nReturned: 1 totalKeysExamined: 0 totalDocsExamined: 5
That result comes from this small collection, which the rest of the lesson uses. To run the commands yourself, insert these documents first:
db.products.insertMany([
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%