开发者

MongoDB Geospacial search and official C# driver

Can some expert point the best ways to a Geospacial search using official C# driver in MongoDB. Best Obj开发者_运维技巧ect constructor(strings /doubles), Build an index, find near. Many thanks for your help.

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


The C# equivalent to those Mongo shell commands is:

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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜