Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mongodb复合地理空间索引性能缓慢_Mongodb_Mongodb Query - Fatal编程技术网

mongodb复合地理空间索引性能缓慢

mongodb复合地理空间索引性能缓慢,mongodb,mongodb-query,Mongodb,Mongodb Query,我有一个名为“位置”的集合,其中一个文档看起来像: { "_id" : ObjectId("5726ad18bdb861058819ea00"), "loc" : { "type" : "Point", "coordinates" : [ -90.426407, 34.850685 ] }, "name" : "restaurant name", "tags"

我有一个名为“位置”的集合,其中一个文档看起来像:

{
    "_id" : ObjectId("5726ad18bdb861058819ea00"),
    "loc" : {
        "type" : "Point",
        "coordinates" : [
            -90.426407,
            34.850685
        ]
    },
    "name" : "restaurant name",
    "tags" : [
        "Chinese",
        "thai",
        "American",
        "indian"
    ]
}
我有以下索引:

db.location.getIndexes()
[
    {
        "v" : 1,
        "key" : {
            "_id" : 1
        },
        "name" : "_id_",
        "ns" : "chatx.location"
    },
    {
        "v" : 1,
        "key" : {
            "loc" : "2dsphere",
            "tags" : 1
        },
        "name" : "loc_2dsphere_tags_1",
        "ns" : "chatx.location",
        "2dsphereIndexVersion" : 3
    }
]
我用标签来识别餐厅的食物类型

我一直在根据食物类型寻找最近的餐馆。我的问题是:

db.runCommand(
   {
     geoNear: "location",
     near: { type: "Point", coordinates: [-90.426407, 34.850685] },
     limit:10,
     maxDistance:5000,
     spherical: true,
     query: { tags:{$all:["chinese", "thai"]}}
   }
)
为了做到这一点,我使用了$geoNear(在3.2版本中这是非常好的性能)。然而,当我结合使用标记(使用$all)时,查询速度会变慢,这是有意义的,因为$all基于第一个元素搜索所有文档,然后基于其他元素进行细化。查询速度变慢的主要原因是增加限制(例如:10到100或更多)和数组元素[“thai”、“indian”、…]。例如,如果我搜索带有4个食物类型标签的餐馆,查询速度会变得非常慢,而不是搜索带有1个食物类型标签的餐馆


我想知道是否有人能帮我找出这个集合的最佳模式,或者提供更好的查询选项

确保为存储的坐标创建索引。除此之外,
$all
不应该太慢,因为它正在处理标记,这应该是一个相对较小的列表。我有一个复合索引,如:“name”:“loc_2dphere_tags_1”,是的,速度很慢(对于2mln记录查询,有点像15秒)Daniele Tassone,我使用1)多键索引2)限制文档数量和3)设置最大和最小距离来提高查询性能。