如何在 mongodb C# 驱动程序 2.4 中使用 GeoWithin

一山

获取用户位置后,我需要使用 GeoWithin 找到接近用户的点,之前是否使用过任何机构?

穆罕默德·塔赫里安

顺便说一下,这是一个near的示例GeoWithin

var point = GeoJson.Point(GeoJson.Geographic(-73.97, 40.77));

var filter = Builders<BsonDocument>.Filter.Near("location", point, 10);
var a = collection.Find(filter1).Any();

var filter2 = Builders<BsonDocument>.Filter.GeoWithin("location", point);
var b = collection.Find(filter2).Any();

你也可以使用GeoWithinPolygonGeoWithinCenter

double[,] polygon = new double[,] { { -73.97, 40.77 }, { -73.9928, 40.7193 }, { -73.9375, 40.8303 }, { -73.97, 40.77 } };

var filter3 = Builders<BsonDocument>.Filter.GeoWithinPolygon("location", polygon);
var c = collection.Find(filter3).Any();

var filter4 = Builders<BsonDocument>.Filter.GeoWithinCenter("location", -73.97, 40.77, 10);
var d = collection.Find(filter4).Any();

希望能帮助到你。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Java mongodb驱动程序中使用“ _id”字段查询文档?

如何使用C#驱动程序检查MongoDB中是否存在集合?

使用C#MongoDB驱动程序,如何序列化对象引用的集合?

如何使用C#驱动程序删除mongodb文档中的嵌套数组元素

如何使用C#2.0驱动程序将数据插入mongodb集合?

如何与MongoDb C#驱动程序2.1异步使用AsQueryable方法?

不知道如何在C#中为MongoDb使用ElemMatch(最新驱动程序版本)

如何使用MongoDB C#驱动程序进行$ lookup?

如何在MongoDB C#驱动程序版本2中使用$位置运算符

C#MongoDB驱动程序-如何使用UpdateDefinitionBuilder?

如何使用C#驱动程序在MongoDB上执行$ setIsSubset?

使用Java驱动程序3.8的ColdFusion和MongoDB 4

如何在MongoDB 2.7中使用MongoDB C#驱动程序更新通用类型

在C#的MongoDB驱动程序中使用$ addFields

如何使用Mongodb C#驱动程序加入多个集合

如何使用C#驱动程序以编程方式在MongoDB查询上设置排序字段?

如何使用NearSphere MongoDB驱动程序C#将距离结果返回到点

如何在C#MongoDB驱动程序聚合管道中使用正则表达式

如何使用MongoDB C#驱动程序聚合$ lookup?

如何使用mongodb C#驱动程序获取子文档的集合?

如何在MongoDB Java驱动程序中使用sureIndex

如何在mongodb中使用$ and运算符-Java驱动程序

MongoDB在新的C驱动程序中使用$ or和$ and

如何在Ubuntu中安装和使用mongodb c ++驱动程序?

如何在Play Framework 2.x操作中使用MongoDB异步Java驱动程序?

mongoDB:C#驱动程序V2如何更新嵌套集合中的项目

如何使用 MongoDB C 驱动程序和 FoundationDB 文档层进行事务?

如何在内核空间中使用 i2c 驱动程序

如何使用 C# 驱动程序获取 MongoDB 中的集群时间