mongodb中查询地理空间数据的最快方法

mongodb中查询地理空间数据的最快方法,mongodb,geospatial,spatial-query,Mongodb,Geospatial,Spatial Query,目前,我的geojson数据以以下格式存储: coord: [long, lat], time: unix timestamp, property: some property 我想找到具有最近时间戳(lte)的最近位置。我现在的做法是: collection.ensureIndex({loc: "2d"}) collection.find( {coord : { $near: [xval, yval]

目前,我的geojson数据以以下格式存储:

  coord: [long, lat],
  time: unix timestamp,
  property: some property
我想找到具有最近时间戳(lte)的最近位置。我现在的做法是:

    collection.ensureIndex({loc: "2d"})
    collection.find(
            {coord : {
                    $near: [xval, yval],
                    $maxDistance: 200
                    },
             time: {
                    $lte: time
             }
            }).sort({time: -1}).limit(1).toArray(function(err, queryResult) {
  (did some return 404 and 200 here)
 }

当数据量很小时,这是可行的。但由于我的数据库已增加到50G+,这将失败(总是返回404,表示未找到任何内容),我认为这是因为我查询数据的方式导致性能降低。我应该如何更改我的查询/数据结构以改进并使其重新工作

您应该首先垂直扩展mongodb,增加更多的ram和CPU电源,直到达到下一个平台。下一步是通过让多个MongoDB实例处理数据集来水平扩展(或切分)DB。当然,切分大大提高了DB性能。您可以阅读其中描述了缩放mongo的基本步骤。

我认为您的查询没有任何问题。如果你有50克以上的数据,你可能需要扩展你的后端。@Eric你介意更具体一点扩展我的后端吗?要么放更多的ram和cpu,要么分片你的后端database@Eric更多的ram和cpu是不可能的。sharding能提高我的表现多少?我会给出一个完整的回答。