gpt4 book ai didi

MongoDB + C# 驱动程序 + 地理空间字段查询 - 如何在实体上定义位置属性

转载 作者:可可西里 更新时间:2023-11-01 10:01:25 25 4
gpt4 key购买 nike

我正在运行 Mongodb 2.06 版和 10Gen 提供的 C# 驱动程序 (1.5) 版。

我想在我的一个实体上有纬度和经度坐标,这样我就可以使用 GeoNear 或 Query.WithinCircle 查询实体。

我正在向我的实体添加一个强类型的 Location 对象,然后在与我的实体 Hook 的 Location 对象上创建一个索引,但我无法使任何 GeoNear 查询正常工作。

这就是我的 Location 实体的样子。

public class Location
{
[BsonDefaultValue(null)]
public Nullable<double> lon { get; set; }

[BsonDefaultValue(null)]
public Nullable<double> lat { get; set; }
}

这就是我所讨论的实体的样子。

  public class SomeEntity
{
public string Field1 {get; set;}

// more fields here...

public Location Loc {get; set;}
}

我找到了这个链接 http://www.mongodb.org/display/DOCS/Geospatial+Indexing/并看到我的位置字段需要是一个数组。如果我的实体 SomeEntity 使用数组字段而不是我的 Location 对象,会是什么样子?

我知道这很简单,但我就是想不通! :-)

谢谢

最佳答案

你可以试试这个:

public class SomeEntity
{
public string Field1 {get; set;}

// more fields here...

public double[] Loc {get; set;}
}

虽然您现有的类应该可以工作(虽然建议使用数组,但唯一真正的要求是该对象由两个数字组成)。我可能不会使用 Nullable 而只是使用 double。

您的地理查询在哪些方面不起作用?

关于MongoDB + C# 驱动程序 + 地理空间字段查询 - 如何在实体上定义位置属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11402033/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com