Mongo $ geoNear查询-错误的nscanned数和错误的结果 [英] Mongo $geoNear query - incorrect nscanned number and incorrect results

查看:60
本文介绍了Mongo $ geoNear查询-错误的nscanned数和错误的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含约6k文档的集合,在位置字段上具有2dsphere索引,如下所示:

I have a collection with around 6k documents with 2dsphere index on location field, example below:

"location" : {
    "type" : "Point",
    "coordinates" : [ 
        138.576187, 
        -35.010441
    ]
}

使用以下查询时,我仅得到约450份文档,其中nscanned约为3k.每个文档都有一个位置,很多位置是重复的.从GeoJSON返回的距离以米为单位,并且距离乘数0.000625会将距离转换为英里.为了进行测试,我期望最大距离为32180000000000,以返回地球上的所有文档,即6000

When using the below query I only get around 450 docs returned with nscanned around 3k. Every document has a location, many locations are duplicated. Distances returned from GeoJSON are in meters, and a distance multiplier of 0.000625 will convert distances to miles. To test, I'm expecting max distance of 32180000000000 to return all the documents on the planet, ie 6000

db.x.aggregate([
{"$geoNear":{
    "near":{
        "type":"Point",
        "coordinates":[-0.3658702,51.45686]
    },
    "distanceField":"distance",
    "limit":100000,
    "distanceMultiplier":0.000625,
    "maxDistance":32180000000000,
    "spherical":true,
}}

])

为什么我不能退回6000个文档?我无法从Mongo中找到此行为背后的逻辑.我在mongo论坛上找到了: "geoNear的主要局限性在于,作为命令,它可以返回最大文档大小的结果集,因为所有匹配的文档都在单个结果文档中返回."

Why dont I get 6000 documents returned? I'm unable to find the logic behind this behaviour from Mongo. I've found on the mongo forums: "geoNear's major limitation is that as a command it can return a result set up to the maximum document size as all of the matched documents are returned in a single result document."

推荐答案

我很确定mongodb对$ GeoNear结果的限制为16 MB.在https://github.com/mongodb/mongo/blob/master/src/mongo/db/commands/geo_near_cmd.cpp 您可以看到,在构建geonear的结果时,存在这种情况

I'm pretty sure that mongodb has a limit of 16 MB on the results of $GeoNear. In https://github.com/mongodb/mongo/blob/master/src/mongo/db/commands/geo_near_cmd.cpp you can see that while the results of the geonear are being built, there's this condition

// Don't make a too-big result object.
if (resultBuilder.len() + resObj.objsize()> BSONObjMaxUserSize) {
    warning() << "Too many geoNear results for query " << rewritten.toString()
              << ", truncating output.";
    break;
}

https://github中. com/mongodb/mongo/blob/master/src/mongo/bson/util/builder.h ,您会看到它的大小限制为16 MB.

And in https://github.com/mongodb/mongo/blob/master/src/mongo/bson/util/builder.h youll see its limited to 16 MB.

const int BSONObjMaxUserSize = 16 * 1024 * 1024;

这篇关于Mongo $ geoNear查询-错误的nscanned数和错误的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆