几天来,我一直在敲打这个.我有一个非常简单的查询,我试图在C#中运行,它在shell中看起来像这样.
db.runCommand({geoNear: "items", near: {type: "Point", coordinates : [-111.283344899999, 47.4941836]}, spherical : true, distanceMultiplier: 3963.2, maxDistance : 25});
Run Code Online (Sandbox Code Playgroud)
我的收藏看起来像这样
{
"_id" : ObjectId(),
"Title" : "arst",
"Description" : "<p>arst</p>",
"Date" : new Date("11/29/2015 09:28:15"),
"Location" : {
"type" : "Point",
"Coordinates" : [-111.28334489999998, 47.4941836]
},
"Zip" : "59405"
}
Run Code Online (Sandbox Code Playgroud)
根据MongoDB C#API文档中的文档,MongoDB.Driver.Builders.Query对象现在已成为遗产.所以,当我做这样的事情
var point = new GeoJson2DGeographicCoordinates(double.Parse(longitude), double.Parse(latitude)) ;
var query = Query<Item>.Near(x => x.Location, new GeoJsonPoint<GeoJson2DGeographicCoordinates>(point), distance, true);
var result = collection.Find(query);
Run Code Online (Sandbox Code Playgroud)
编译器抱怨它无法从IMongoQuery转换为FilterDefinition.这告诉我新的2.1库不支持旧的Query <>构建器.但是对于我的生活,我在api文档中找不到任何引用替换的文档?
有没有人能指出我在2.1 C#驱动程序中执行这个简单的地理空间查询的正确方向?我很难过.
此外,我确实在集合上创建了一个2dsphere索引,如果我没有shell命令不起作用.这是索引输出.
{ …Run Code Online (Sandbox Code Playgroud) 我正在使用9.6版本.我的文档看起来像这样:
{
"name" : "John Doe",
"phones" : [
{
"type" : "mobile",
"number" : "555-555-0000",
"deleted": false
},
{
"type" : "home",
"number" : "555-555-0001",
"needsUpdated" : true
},
{
"type" : "work",
"number" : "555-555-0002"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我创建了这样的:
create table t_json (c_json json not null);
insert into t_json (c_json) values ('{"name":"John Doe","phones": [{"type":"mobile","number":"555-555-0000"},{"type":"home","number":"555-555-0001"},{"type": "work","number": "555-555-0002"}]}');
insert into t_json (c_json) values ('{"name":"Jane Dane","phones": [{"type":"mobile","number":"555-555-0030"},{"type":"home","number":"555-555-0020"},{"type": "work","number": "555-555-0010"}]}');
Run Code Online (Sandbox Code Playgroud)
现在我想弄清楚如何A,选择名为John Doe的行,并将他的手机号码更新为"555-555-0003".
从这里Postgresql 9.6文档我发现我可以查询正确的文档,如下所示:
select c_json …Run Code Online (Sandbox Code Playgroud)