MongoDB$GeoInner查询速度非常慢

MongoDB$GeoInner查询速度非常慢,mongodb,performance,mongodb-query,geospatial,Mongodb,Performance,Mongodb Query,Geospatial,我收集了大量文档(约100万),每个文档都相当大(avgObjSize:13268)。每个文档都有一个地理点: Accomodation: { "location" : { [...] "geoLocation" : { "type" : "Point", "coordinates" : [ -42.61343486,

我收集了大量文档(约100万),每个文档都相当大(avgObjSize:13268)。每个文档都有一个地理点:

Accomodation:
    {
       "location" : {
            [...]
            "geoLocation" : {
                "type" : "Point",
                "coordinates" : [ 
                    -42.61343486, 
                    71.70936503
                ]
            }
        }
    }
我有以下索引:

{
    "location.geoLocation" : "2dsphere"
}
我做这个简单的查询(应该保持85公里的半径):

查询执行需要1到6秒的时间,我认为这很慢。 即使服务器电量不足,获取100个文档所需的时间也应该少很多,因为它似乎使用了索引,因此该区域中的文档甚至不应该被提取用于扫描。 我错过了什么

这是查询统计信息

{
    "queryPlanner" : {
        "plannerVersion" : 1,
        "namespace" : "Stage-BluePillow.Accomodation",
        "indexFilterSet" : false,
        "parsedQuery" : {
            "location.geoLocation" : {
                "$geoWithin" : {
                    "$centerSphere" : [ 
                        [ 
                            2.34682537615297, 
                            48.8536252472747
                        ], 
                        0.0131543876703093
                    ]
                }
            }
        },
        "winningPlan" : {
            "stage" : "LIMIT",
            "limitAmount" : 100,
            "inputStage" : {
                "stage" : "FETCH",
                "filter" : {
                    "location.geoLocation" : {
                        "$geoWithin" : {
                            "$centerSphere" : [ 
                                [ 
                                    2.34682537615297, 
                                    48.8536252472747
                                ], 
                                0.0131543876703093
                            ]
                        }
                    }
                },
                "inputStage" : {
                    "stage" : "IXSCAN",
                    "keyPattern" : {
                        "location.geoLocation" : "2dsphere"
                    },
                    "indexName" : "location.geoLocation_2dsphere",
                    "isMultiKey" : false,
                    "isUnique" : false,
                    "isSparse" : false,
                    "isPartial" : false,
                    "indexVersion" : 1,
                    "direction" : "forward",
                    "indexBounds" : {
                        "location.geoLocation" : [ 
                            "[5116089176692883456, 5116089176692883456]", 
                            "[5170132372221329408, 5170132372221329408]", 

                            [...]

                            "[5183361696126730241, 5183502433615085567]", 
                            "[5183643171103440896, 5183643171103440896]"
                        ]
                    }
                }
            }
        },

    "executionStats" : {
        "executionSuccess" : true,
        "nReturned" : 100,
        "executionTimeMillis" : 1399,
        "totalKeysExamined" : 151,
        "totalDocsExamined" : 142,
        "executionStages" : {
            "stage" : "LIMIT",
            "nReturned" : 100,
            "executionTimeMillisEstimate" : 1180,
            "works" : 152,
            "advanced" : 100,
            "needTime" : 51,
            "needYield" : 0,
            "saveState" : 35,
            "restoreState" : 35,
            "isEOF" : 1,
            "invalidates" : 0,
            "limitAmount" : 100,
            "inputStage" : {
                "stage" : "FETCH",
                "filter" : {
                    "location.geoLocation" : {
                        "$geoWithin" : {
                            "$centerSphere" : [ 
                                [ 
                                    2.34682537615297, 
                                    48.8536252472747
                                ], 
                                0.0131543876703093
                            ]
                        }
                    }
                },
                "nReturned" : 100,
                "executionTimeMillisEstimate" : 1180,
                "works" : 151,
                "advanced" : 100,
                "needTime" : 51,
                "needYield" : 0,
                "saveState" : 35,
                "restoreState" : 35,
                "isEOF" : 0,
                "invalidates" : 0,
                "docsExamined" : 142,
                "alreadyHasObj" : 0,
                "inputStage" : {
                    "stage" : "IXSCAN",
                    "nReturned" : 142,
                    "executionTimeMillisEstimate" : 40,
                    "works" : 151,
                    "advanced" : 142,
                    "needTime" : 9,
                    "needYield" : 0,
                    "saveState" : 35,
                    "restoreState" : 35,
                    "isEOF" : 0,
                    "invalidates" : 0,
                    "keyPattern" : {
                        "location.geoLocation" : "2dsphere"
                    },
                    "indexName" : "location.geoLocation_2dsphere",
                    "isMultiKey" : false,
                    "isUnique" : false,
                    "isSparse" : false,
                    "isPartial" : false,
                    "indexVersion" : 1,
                    "direction" : "forward",
                    "indexBounds" : {
                        "location.geoLocation" : [ 
                            "[5116089176692883456, 5116089176692883456]", 
                            "[5170132372221329408, 5170132372221329408]", 

                            [...]

                            "[5183361696126730241, 5183502433615085567]", 
                            "[5183643171103440896, 5183643171103440896]"
                        ]
                    },
                    "keysExamined" : 151,
                    "dupsTested" : 0,
                    "dupsDropped" : 0,
                    "seenInvalidated" : 0
                }
            }
        }
    },
    "serverInfo" : {
        "host" : "metasearch",
        "port" : 27017,
        "version" : "3.2.10",
        "gitVersion" : "79d9b3ab5ce20f51c272b4411202710a082d0317"
    },
    "ok" : 1.0
}

两个月过去了,我仍然有这个问题,我不知道如何解决。你找到解决办法了吗?没有。我认为这是预期的行为,因此必须获取地理查询中涉及的文档。我可能会创建一个只包含点和文档id的专用集合,这样获取的文档会更轻。然后我可能会在更大的区域查询上使用另一个索引。您现在找到解决方案了吗?正如前面的评论中所述:我认为$geointen不是一个线性操作,因此不能用于“infinete”集合。当我搜索住宿时,我总是有一个搜索区域,比如一个城市或一个州,让我们把它命名为“项目”,它有一个id。所以我预先计算了项目区域中的住宿,并将项目id添加到住宿中的和数组中。将索引添加到数组中并在其上进行查询是非常有效的。如果没有该项目,我将从$centerSphere中包含的较小项目中搜索
{
    "queryPlanner" : {
        "plannerVersion" : 1,
        "namespace" : "Stage-BluePillow.Accomodation",
        "indexFilterSet" : false,
        "parsedQuery" : {
            "location.geoLocation" : {
                "$geoWithin" : {
                    "$centerSphere" : [ 
                        [ 
                            2.34682537615297, 
                            48.8536252472747
                        ], 
                        0.0131543876703093
                    ]
                }
            }
        },
        "winningPlan" : {
            "stage" : "LIMIT",
            "limitAmount" : 100,
            "inputStage" : {
                "stage" : "FETCH",
                "filter" : {
                    "location.geoLocation" : {
                        "$geoWithin" : {
                            "$centerSphere" : [ 
                                [ 
                                    2.34682537615297, 
                                    48.8536252472747
                                ], 
                                0.0131543876703093
                            ]
                        }
                    }
                },
                "inputStage" : {
                    "stage" : "IXSCAN",
                    "keyPattern" : {
                        "location.geoLocation" : "2dsphere"
                    },
                    "indexName" : "location.geoLocation_2dsphere",
                    "isMultiKey" : false,
                    "isUnique" : false,
                    "isSparse" : false,
                    "isPartial" : false,
                    "indexVersion" : 1,
                    "direction" : "forward",
                    "indexBounds" : {
                        "location.geoLocation" : [ 
                            "[5116089176692883456, 5116089176692883456]", 
                            "[5170132372221329408, 5170132372221329408]", 

                            [...]

                            "[5183361696126730241, 5183502433615085567]", 
                            "[5183643171103440896, 5183643171103440896]"
                        ]
                    }
                }
            }
        },

    "executionStats" : {
        "executionSuccess" : true,
        "nReturned" : 100,
        "executionTimeMillis" : 1399,
        "totalKeysExamined" : 151,
        "totalDocsExamined" : 142,
        "executionStages" : {
            "stage" : "LIMIT",
            "nReturned" : 100,
            "executionTimeMillisEstimate" : 1180,
            "works" : 152,
            "advanced" : 100,
            "needTime" : 51,
            "needYield" : 0,
            "saveState" : 35,
            "restoreState" : 35,
            "isEOF" : 1,
            "invalidates" : 0,
            "limitAmount" : 100,
            "inputStage" : {
                "stage" : "FETCH",
                "filter" : {
                    "location.geoLocation" : {
                        "$geoWithin" : {
                            "$centerSphere" : [ 
                                [ 
                                    2.34682537615297, 
                                    48.8536252472747
                                ], 
                                0.0131543876703093
                            ]
                        }
                    }
                },
                "nReturned" : 100,
                "executionTimeMillisEstimate" : 1180,
                "works" : 151,
                "advanced" : 100,
                "needTime" : 51,
                "needYield" : 0,
                "saveState" : 35,
                "restoreState" : 35,
                "isEOF" : 0,
                "invalidates" : 0,
                "docsExamined" : 142,
                "alreadyHasObj" : 0,
                "inputStage" : {
                    "stage" : "IXSCAN",
                    "nReturned" : 142,
                    "executionTimeMillisEstimate" : 40,
                    "works" : 151,
                    "advanced" : 142,
                    "needTime" : 9,
                    "needYield" : 0,
                    "saveState" : 35,
                    "restoreState" : 35,
                    "isEOF" : 0,
                    "invalidates" : 0,
                    "keyPattern" : {
                        "location.geoLocation" : "2dsphere"
                    },
                    "indexName" : "location.geoLocation_2dsphere",
                    "isMultiKey" : false,
                    "isUnique" : false,
                    "isSparse" : false,
                    "isPartial" : false,
                    "indexVersion" : 1,
                    "direction" : "forward",
                    "indexBounds" : {
                        "location.geoLocation" : [ 
                            "[5116089176692883456, 5116089176692883456]", 
                            "[5170132372221329408, 5170132372221329408]", 

                            [...]

                            "[5183361696126730241, 5183502433615085567]", 
                            "[5183643171103440896, 5183643171103440896]"
                        ]
                    },
                    "keysExamined" : 151,
                    "dupsTested" : 0,
                    "dupsDropped" : 0,
                    "seenInvalidated" : 0
                }
            }
        }
    },
    "serverInfo" : {
        "host" : "metasearch",
        "port" : 27017,
        "version" : "3.2.10",
        "gitVersion" : "79d9b3ab5ce20f51c272b4411202710a082d0317"
    },
    "ok" : 1.0
}