查看MongoDB Quick Start的源代码
←
MongoDB Quick Start
跳转到:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您刚才请求的操作只有这个用户组中的用户才能使用:
用户
您可以查看并复制此页面的源代码:
== Index == <source lang=bash> > for (i=0; i<200000; i++){ ... db.numbers.save({num:i}); ... } > db.numbers.count() 200000 > db.numbers.find() { "_id" : ObjectId("548ff09c991680933fb5a00b"), "num" : 0 } { "_id" : ObjectId("548ff09c991680933fb5a00c"), "num" : 1 } { "_id" : ObjectId("548ff09c991680933fb5a00d"), "num" : 2 } { "_id" : ObjectId("548ff09c991680933fb5a00e"), "num" : 3 } { "_id" : ObjectId("548ff09c991680933fb5a00f"), "num" : 4 } { "_id" : ObjectId("548ff09c991680933fb5a010"), "num" : 5 } { "_id" : ObjectId("548ff09c991680933fb5a011"), "num" : 6 } { "_id" : ObjectId("548ff09c991680933fb5a012"), "num" : 7 } { "_id" : ObjectId("548ff09c991680933fb5a013"), "num" : 8 } { "_id" : ObjectId("548ff09c991680933fb5a014"), "num" : 9 } { "_id" : ObjectId("548ff09c991680933fb5a015"), "num" : 10 } { "_id" : ObjectId("548ff09c991680933fb5a016"), "num" : 11 } { "_id" : ObjectId("548ff09c991680933fb5a017"), "num" : 12 } { "_id" : ObjectId("548ff09c991680933fb5a018"), "num" : 13 } { "_id" : ObjectId("548ff09c991680933fb5a019"), "num" : 14 } { "_id" : ObjectId("548ff09c991680933fb5a01a"), "num" : 15 } { "_id" : ObjectId("548ff09c991680933fb5a01b"), "num" : 16 } { "_id" : ObjectId("548ff09c991680933fb5a01c"), "num" : 17 } { "_id" : ObjectId("548ff09c991680933fb5a01d"), "num" : 18 } { "_id" : ObjectId("548ff09c991680933fb5a01e"), "num" : 19 } has more > it { "_id" : ObjectId("548ff09c991680933fb5a01f"), "num" : 20 } { "_id" : ObjectId("548ff09c991680933fb5a020"), "num" : 21 } { "_id" : ObjectId("548ff09c991680933fb5a021"), "num" : 22 } { "_id" : ObjectId("548ff09c991680933fb5a022"), "num" : 23 } { "_id" : ObjectId("548ff09c991680933fb5a023"), "num" : 24 } { "_id" : ObjectId("548ff09c991680933fb5a024"), "num" : 25 } { "_id" : ObjectId("548ff09c991680933fb5a025"), "num" : 26 } { "_id" : ObjectId("548ff09c991680933fb5a026"), "num" : 27 } { "_id" : ObjectId("548ff09c991680933fb5a027"), "num" : 28 } { "_id" : ObjectId("548ff09c991680933fb5a028"), "num" : 29 } { "_id" : ObjectId("548ff09c991680933fb5a029"), "num" : 30 } { "_id" : ObjectId("548ff09c991680933fb5a02a"), "num" : 31 } { "_id" : ObjectId("548ff09c991680933fb5a02b"), "num" : 32 } { "_id" : ObjectId("548ff09c991680933fb5a02c"), "num" : 33 } { "_id" : ObjectId("548ff09c991680933fb5a02d"), "num" : 34 } { "_id" : ObjectId("548ff09c991680933fb5a02e"), "num" : 35 } { "_id" : ObjectId("548ff09c991680933fb5a02f"), "num" : 36 } { "_id" : ObjectId("548ff09c991680933fb5a030"), "num" : 37 } { "_id" : ObjectId("548ff09c991680933fb5a031"), "num" : 38 } { "_id" : ObjectId("548ff09c991680933fb5a032"), "num" : 39 } has more > db.numbers.find({num:500}) { "_id" : ObjectId("548ff09c991680933fb5a1ff"), "num" : 500 } > db.numbers.find({num:{"$gt":199997}}) { "_id" : ObjectId("548ff0b1991680933fb8ad49"), "num" : 199998 } { "_id" : ObjectId("548ff0b1991680933fb8ad4a"), "num" : 199999 } > db.numbers.find({num:{"$gt":33,"$lt":36}}) { "_id" : ObjectId("548ff09c991680933fb5a02d"), "num" : 34 } { "_id" : ObjectId("548ff09c991680933fb5a02e"), "num" : 35 } > db.numbers.find({num:{"$gt":199997}}).explain() { "cursor" : "BasicCursor", "indexBounds" : [ ], "nscanned" : 200000, "nscannedObjects" : 200000, "n" : 2, "millis" : 60, "oldPlan" : { "cursor" : "BasicCursor", "indexBounds" : [ ] }, "allPlans" : [ { "cursor" : "BasicCursor", "indexBounds" : [ ] } ] } </source> Find a line, the time is 60ms Use Indexes: <source lang=bash> > db.numbers.ensureIndex({num:1}) > db.numbers.getIndexes() [ { "name" : "_id_", "ns" : "test.numbers", "key" : { "_id" : 1 } }, { "_id" : ObjectId("548ff1ea991680933fb8ad4b"), "ns" : "test.numbers", "key" : { "num" : 1 }, "name" : "num_1" } ] > db.numbers.find({num:{"$gt":199997}}).explain() { "cursor" : "BtreeCursor num_1", "indexBounds" : [ [ { "num" : 199997 }, { "num" : 1.7976931348623157e+308 } ] ], "nscanned" : 3, "nscannedObjects" : 2, "n" : 2, "millis" : 0, "allPlans" : [ { "cursor" : "BtreeCursor num_1", "indexBounds" : [ [ { "num" : 199997 }, { "num" : 1.7976931348623157e+308 } ] ] } ] } </source> The time is less than 1ms <br><br>
返回到
MongoDB Quick Start
。
个人工具
登录
名字空间
页面
讨论
变换
查看
阅读
查看源代码
查看历史
操作
搜索
导航
首页
社区专页
新闻动态
最近更改
随机页面
帮助
工具箱
链入页面
相关更改
特殊页面