【问题标题】:Is there any way to skip some documents in GeoNear() MongoDB method?有什么方法可以跳过 GeoNear() MongoDB 方法中的一些文档?
【发布时间】:2012-06-22 14:28:30
【问题描述】:

假设我收集了具有指定经度和纬度的文档。

type is specified:

{
    id: ObjectId,
    location : {double, double}, /*array, that contains
                                   just longitude and latitude*/
    someUsefulData : string
}

我需要获取位于某个位置周围 50 英里区域内的所有文件。为此,我正在使用这样的方法:

// set GetNear() options
var options = new GeoNearOptionsBuilder()
    .SetMaxDistance(50) // meens 50 miles
    .SetSpherical(true);

// create conditions query
var conditions = Query.NE("someUsefulData ", $ne : {null});

// execute GetNear()
var geoNearResult = collection
    .GeoNear(conditions, longitude, latitude, limit, options);

这部分效果很好。

但是。

我需要从一开始就跳过一些结果 - 对于经典的分页实现。也许,有人知道如何做到这一点,考虑到 GeoNear() 返回 GeoNearResult - 这不是 MongoCursor,所以我不能使用 SetSkip(20),例如。

【问题讨论】:

    标签: c# mongodb mongodb-.net-driver


    【解决方案1】:

    我建议将限制设置为 limit+20 并跳过应用程序中的前 20 个文档。此外,您可以投票给https://jira.mongodb.org/browse/SERVER-3925,这将为 geoNear 命令添加原生跳过选项。

    【讨论】:

    • 据我所知,geoNear 不返回光标,而是返回数据。因此,在执行此命令后,limit 中指定的全部数据将从 db 加载。我错了吗?
    • 顺便说一句,谢谢你的链接,这是我需要的。所以现在我确定没有办法在 geoNear 中简单地跳过。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-15
    • 2016-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多