Mongo DB $near C# 中的查询

本文关键字:查询 near DB Mongo | 更新日期: 2023-09-27 18:22:46

var query ="{'Geo':{'$near': {'$geometry': {'type': 'Point' ,'coordinates':[]} }}}";
var parsing = BsonDocument.Parse(query);
var qwithcoor = parsing["Geo"]["$near"]["$geometry"]["coordinates"].AsBsonArray;
qwithcoor.AddRange(coordinates);
parsing["Geo"]["$near"].AsBsonDocument.Add("$maxDistance", radius);
var collection = database.GetCollection<BsonDocument>("mycollection");
var documents = await collection.Find(parsing).ToListAsync();

我想用Builders<BsonDocument>.Filter来做这件事.喜欢这个:

var query=Builders<BsonDocument>.Filter.Near();
var documents=await collection.Find(query).ToListAsync();

我是否在过滤器后使用"附近"?什么是邻近参数?

Mongo DB $near C# 中的查询

我用

var gp =new GeoJsonPoint<GeoJson2DGeographicCoordinates>(new GeoJson2DGeographicCoordinates(coordinates[0], coordinates[1]));
var query=Builders<BsonDocument>.Filter.Near("Geo",gp,radius);
var result = await col.Find(query).ToListAsync();