【发布时间】:2011-10-23 00:32:58
【问题描述】:
我一直在尝试开始,但一次又一次地尝试使用 C# 官方驱动程序创建和查询 MongoDB。问题是如何使用地理信息创建数据。我只是没有找到答案。
代码:
MongoUrl url = new MongoUrl("mongodb://xxx.xx.x.xx/mydb");
MongoServer server = MongoServer.Create(url);
MongoDatabase database = server.GetDatabase("mydb");
BsonDocument[] batch = {
new BsonDocument {
{ "name", "Bran" },
{ "loc", "10, 10" }
},
new BsonDocument {
{ "name", "Ayla" },
{ "loc", "0, 0" }
}
};
places.InsertBatch(batch);
places.EnsureIndex(IndexKeys.GeoSpatial("loca"));
var queryplaces = Query.WithinCircle("loca", 0, 0, 11);
var cursor = places.Find(queryplaces);
foreach (var hit in cursor)
{
foreach (var VARIABLE in hit)
{
Console.WriteLine(VARIABLE.Value);
}
}
【问题讨论】:
标签: c# mongodb geocoding geospatial mongodb-.net-driver