Professional Documents
Culture Documents
∞,
5)
[-‐
[5,
10)
[10,
∞)
∞,
5)
buckets
[-‐
[5,
7) [7,
9) [9,
10)
[10,
∞)
buckets
{...} {...} {...} {...} {...} {...} {...} {...} {...} {...} {...}
db.blogs.ensureIndex({author: 1})
1
=
ascending
-‐1
=
descending
db.blogs.save({
author:
"James",
ts:
new
Date()
});
db.blogs.save({
...
title:
"My
first
blog"
});
db.blogs.ensureIndex({"stats.followers": -‐1})
db.blogs.ensureIndex({"comments.author": 1})
db.blogs.find({"comments.author": "James"})
db.blogs.ensureIndex({tags: 1})
db.blogs.find({tags: "NoSQL"})
db.blogs.ensureIndex({author: 1})
db.blogs.find({author:
"James"},
{author:
1,
_id:0}))
db.blogs.save({url:"www.10gen.com"})
db.blogs.save({
loc:
[40.739037,
40.739037]
});
db.blogs.ensureIndex({"loc": "2d"})
db.blogs.getIndexes()
db.blogs.totalIndexSize()
db.blogs.dropIndex({"author": 1})
db.c.find({b:
0})
db.c.find({a:
{$ne:
1}
})
db.c.find({a:
{$nin:
[1,
3,
5,
7]}
})
scan
terminated
index
on
x
db.blogs.find({title:"My blog"}).explain();
db.blogs.find({title:"My blog"}).explain();
{
"cursor"
:
"BasicCursor",
"indexBounds"
:
{}
"nscanned"
:
57594,
"nscannedObjects"
:
57594,
"n"
:
3,
"millis"
:
108
}
db.blogs.ensureIndex({title:
1});
db.blogs.find({title:
"My
blog"}).explain();
{
"cursor"
:
"BtreeCursor
x_1",
"indexBounds"
:
{...},
"nscanned"
:
123,
"nscannedObjects"
:
123,
"n"
:
10,
"millis"
:
4
}
db.blogs.ensureIndex({title:
1});
db.blogs.find({title:
"My
blog"},
{title:
1,
_id:
0}).explain();
{
"cursor"
:
"BtreeCursor
x_1",
"indexBounds"
:
{...},
"nscanned"
:
123,
"nscannedObjects"
:
123,
"n"
:
10,
"millis"
:
4,
"indexOnly"
:
true
}
1 2 3 4 5 6 6 6 9
{_id:4,x:6} {_id:5,x:6}
{_id:1,x:6}
Wednesday, May 25, 2011 27
Equality match
db.c.find({x:6}).explain()
{
"cursor"
:
"BtreeCursor
x_1",
"nscanned"
:
3,
"nscannedObjects"
:
3,
"n"
:
3,
"millis"
:
1,
"nYields"
:
0,
"nChunkSkips"
:
0,
"isMultiKey"
:
false,
"indexOnly"
:
false,
"indexBounds"
:
{
"x"
:
[
[
6,
6
]
]
}
}
2 6
1 3 4 6 6 9
1 2 3 4 5 6 6 6 9
{y:4,x:6} {y:5,x:6}
{y:1,x:6}
Wednesday, May 25, 2011 32
Full document match
db.c.find({x:
6,
y:
1}).explain()
{
"cursor"
:
"BtreeCursor
x_1",
"nscanned"
:
3,
"nscannedObjects"
:
3,
"n"
:
1,
"millis"
:
1,
"nYields"
:
0,
"nChunkSkips"
:
0,
"isMultiKey"
:
false,
"indexOnly"
:
false,
"indexBounds"
:
{
"x"
:
[
[
6,
6
]
]
}
}
1 2 3 4 5 6 7 8 9
2 7
1 3 4 6 8 9
insert
query
update
delete
getmore
command
flushes
mapped
vsize
res
locked
%
idx
miss
%
5345
0
0
0
0
1
0
8.75g
11.1g
132m
1
2
230
0
0
0
0
1
0
8.75g
11.1g
132m
1
7
1740
20
0
0
0
2
0
8.75g
11.1g
132m
3
19
0
120
0
0
0
1
0
8.75g
11.1g
132m
0
17
0
117
0
0
0
1
0
8.75g
11.1g
132m
0
16
0
119
0
0
0
1
0
8.75g
11.1g
132m
0
17
We’re Hiring !
alvin@10gen.com