19. When is an Index Used?
Index
on
{a:
1}
db.collection.find({a:
0})
db.collection.find({a:
{$in:
[0,
2]}})
db.collection.find({a:
{$gt:
5}})
db.collection.count({a:
0})
db.collection.find().sort({a:
-‐1})
Partially:
db.collection.find({b:
0}).sort({a:
-‐1})
20. When isn’t an Index Used?
Index
on
{a:
1,
b:
-‐1}
db.collection.find({b:
0})
As
a
rule:
try
imagining
how
the
sorted
representation
could
help
the
server
with
your
query.
21. Picking an Index
find({x:
10,
y:
“foo”})
scan
terminate
index
on
x
index
on
y remember
22. When are Indexes
Needed?
Frequently
used
queries
Low
response
time