如何使用GeoWithin与mongodb C#Driver 2.4

时间:2017-07-24 09:18:36

标签: mongodb mongodb-.net-driver

我需要使用GeoWithin在找到他的位置之后找到几乎指向用户,之前是否使用过任何身体?

1 个答案:

答案 0 :(得分:1)

顺便说一下,这是nearGeoWithin的示例:

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();

希望有帮助。