【发布时间】:2012-10-25 17:57:57
【问题描述】:
基于mongodbdocumentation
ensureIndex() 函数仅在索引不存在时创建索引。
一旦一个集合被一个键索引,随机访问匹配的查询表达式 指定的键很快。如果没有索引,MongoDB 必须遍历每个文档来检查查询中指定键的值:
db.things.find({j:2}); // fast - uses index
db.things.find({x:3}); // slow - has to check all because 'x' isn't
这是否意味着第一行代码运行时是big_theta = 1,第二行代码是big_theta = n?
【问题讨论】:
-
@SergioTulentsev 你应该发布作为答案,并获得积分! :)
-
@LaneLane:太晚了,已经有答案了:)
标签: algorithm mongodb indexing runtime