【发布时间】:2014-07-09 19:49:30
【问题描述】:
首先:我已经根据MongoDB查询性能看了很多帖子,但没有找到好的解决方案。
在集合内部,文档结构如下:
{
"_id" : ObjectId("535c4f1984af556ae798d629"),
"point" : [
-4.372925494081455,
41.367710205649544
],
"location" : [
{
"x" : -7.87297955453618,
"y" : 73.3680160842939
},
{
"x" : -5.87287143362673,
"y" : 73.3674043270052
}
],
"timestamp" : NumberLong("1781389600000")
}
我的收藏已经有了索引:
db.collection.ensureIndex({timestamp:-1})
查询如下:
db.collection.find({ "timestamp" : { "$gte" : 1380520800000 , "$lte" : 1380546000000}})
尽管如此,响应时间太长了,大约 20 - 30 秒(这个时间取决于指定的查询参数)
任何帮助都是有用的!
提前致谢。
编辑:我更改了查找参数,将它们替换为真实数据。
上述查询耗时46秒,这是explain()函数给出的信息:
{
"cursor" : "BtreeCursor timestamp_1",
"isMultiKey" : false,
"n" : 124494,
"nscannedObjects" : 124494,
"nscanned" : 124494,
"nscannedObjectsAllPlans" : 124494,
"nscannedAllPlans" : 124494,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 45,
"nChunkSkips" : 0,
"millis" : 46338,
"indexBounds" : {
"timestamp" : [
[
1380520800000,
1380558200000
]
]
},
"server" : "ip-XXXXXXXX:27017"
}
【问题讨论】:
-
如果您的意图是地理位置查询,您可能需要考虑使用不同的文档结构。但除此之外,您的查询看起来比实际更具理论性(因为时间戳值显然不在您指定的范围内)并且理论问题很少得到有意义的答案。 “1000 万条记录”查询中还涉及很多变量,除非您可以更具体,否则这些变量的覆盖范围非常广泛。请尝试并提出一个非常具体的案例。
-
我同意您的搜索本身获得了 124K 记录,这并没有太大的改进空间
标签: mongodb performance indexing nosql