Grokking MongoDB
Vote

0% completed

​

Compound Indexes

Two queries mention the same two fields and use the same index, yet one reads 3 index entries to return 3 orders, while the other reads 7 entries and 7 documents to return 4. The difference is entirely in the order of the fields in the index, and you can see it in these orders:

db.orders.insertMany([ { order_id: 1, customer: "John Doe", total: 150, date: new Date("2023-01-01") }, { order_id: 2, customer: "Jane Smith", total: 200, date: new Date("2023-01-02") }, { order_id: 3, customer: "Emily Davis", total: 300, date: new Date("2023-01-03") },

.....

.....

.....

Like the course? Get enrolled and start learning!

Reading Progress

0%


Vote for new content