每题 - 我使用的是官方的mongodb驱动程序,我正在寻找在给定边界框内的所有POI。Mongo db/C# - 如何做边界框查询?
到目前为止,我有:
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)
{
}
可惜的是,这并不工作。我得到:
QueryFailure标志是类型中未知$:0(回应是{ “$ ERR”: “类型中未知$:0”, “密码”:13058})。
谢谢队友 - 我开始觉得司机不支持这个! – Yannis 2012-02-09 18:37:20
@Yannis,你试过这个吗?'BsonDocument locDoc = new BsonDocument {“$ within”,{“$ box”,new BsonArray(new [] {lowerLeftDoc,upperRightDoc})}}' }; – RameshVel 2012-02-09 18:45:13
或者你也可以试试mongodb-csharp官方论坛http://groups.google.com/group/mongodb-csharp .. – RameshVel 2012-02-09 18:46:01