6

一些专家能否指出使用 MongoDB 中的官方 C# 驱动程序进行地理空间搜索的最佳方法。最佳对象构造函数(字符串/双精度),建立索引,找到附近。非常感谢您的帮助。

db.places.ensureIndex( { loc : "2d" } , { min : -500 , max : 500 } ),  
db.places.find( { loc : { $near : [50,50] , $maxDistance : 5 } } ).limit(20),
4

1 回答 1

8

与这些 Mongo shell 命令等效的 C# 是:

places.EnsureIndex(IndexKeys.GeoSpatial("loc"), IndexOptions.SetGeoSpatialRange(-500, 500));
var query = Query.Near("loc", 50, 50, 5);
var cursor = places.Find(query).SetLimit(20);
foreach (var hit in cursor) {
    // process hit
}
于 2011-02-19T19:49:34.690 回答