Mongo db/C#-如何进行边界框查询?

Mongo db/C#-如何进行边界框查询?,c#,mongodb,mongodb-.net-driver,nosql,C#,Mongodb,Mongodb .net Driver,Nosql,每个标题-我正在使用官方的mongodb驱动程序,我希望获得给定边界框内的所有POI 到目前为止,我已经: MongoCollection<BsonDocument> collection = _MongoDatabase.GetCollection("pois"); BsonArray lowerLeftDoc = new BsonArray(new[] { lowerLeft.Lon, lowerLeft.Lat}); BsonArray upperRightDoc = new

每个标题-我正在使用官方的mongodb驱动程序,我希望获得给定边界框内的所有POI

到目前为止,我已经:

MongoCollection<BsonDocument> collection = _MongoDatabase.GetCollection("pois");

BsonArray lowerLeftDoc = new BsonArray(new[] { lowerLeft.Lon, lowerLeft.Lat});
BsonArray upperRightDoc = new BsonArray(new[] { upperRight.Lon, upperRight.Lat});

BsonDocument locDoc = new BsonDocument 
{
   { "$within", new BsonArray(new[] { lowerLeftDoc, upperRightDoc})}
};

BsonDocument queryDoc = new BsonDocument { { "loc", locDoc }};

IList<TrafficUpdate> updates = new List<TrafficUpdate>();
var results = collection.Find(new QueryDocument(queryDoc)).SetLimit(limit);
foreach (BsonDocument t in results)
{
} 
MongoCollection集合=_MongoDatabase.GetCollection(“POI”);
BsonArray lowerLeftDoc=新的BsonArray(new[]{lowerLeft.Lon,lowerLeft.Lat});
BsonArray upperRightDoc=新的BsonArray(新[]{upperRight.Lon,upperRight.Lat});
BsonDocument locDoc=新的BsonDocument
{
{“$within”,新的BsonArray(新[]{lowerLeftDoc,upperRightDoc}
};
BsonDocument queryDoc=新的BsonDocument{{“loc”,locDoc};
IList updates=新列表();
var results=collection.Find(新QueryDocument(queryDoc)).SetLimit(limit);
foreach(结果中的B文件)
{
} 
不幸的是,这不起作用。我得到:

QueryFailure标志在类型0中为未知$(响应为{“$err”: 类型0中的未知$,“代码:13058})


代码中的问题是没有指定要使用的地理操作。您只在中指定了
$,但在
中遗漏了
。必须在
中指定
$以及
$框
(边界框)、
$多边形
$中心
$中心球
/
$近球

这是运行
$box
查询的正确mongo语法

> box = [[40.73083, -73.99756], [40.741404,  -73.988135]]
> db.places.find({"loc" : {"$within" : {"$box" : box}}})

我不确定c#mongodb语法。但是如果包含“$box”,它将起作用

您也可以使用查询生成器进行此查询:

var query = Query.Within("loc", lowerLeft.Lon, lowerLeft.Lat,
    upperRight.Lon, upperRight.Lat);

让查询生成器来担心创建正确格式查询的细节。

谢谢,伙计-我开始认为驱动程序不支持这一点@Yannis,你试过这个吗<代码>BsonDocument locDoc=新BsonDocument{{{“$within”,{“$box”,新BsonArray(新[]{lowerLeftDoc,upperRightDoc}}}
};或者你可以试试mongodb csharp官方论坛。。