如何通过 C# 驱动程序创建 2dsphere 索引

本文关键字:2dsphere 索引 创建 驱动程序 何通过 | 更新日期: 2023-09-27 18:32:39

>我正在尝试这样做

db.points.ensureIndex( { <location field> : "2dsphere" } )

http://docs.mongodb.org/manual/core/2dsphere/

通过 C# 驱动程序。 但 API 看起来只将"key"作为参数,无法指定类型

http://api.mongodb.org/csharp/current/html/3871579f-5b7c-1d9f-e66d-2403c9280e80.htm

知道如何通过驱动程序做到这一点吗?

谢谢

如何通过 C# 驱动程序创建 2dsphere 索引

假设您有一个名为"location"的字段,其中包含"类型"和"坐标",即它看起来像下面:

{ _id : ...,
  ...,
  'location' : {
         'type' : 'Point',
         'coordinates' : [ longValue, latValue]
   }
}

为了在"位置"字段上创建 2dsphere 索引,我们按如下方式执行此操作:

Collection.CreateIndex(IndexKeys.GeoSpatialSpherical("location"));

键是整个对象

"{ "位置" : "2dsphere" }"

我有错误的理解

在这里发帖,以防有人遇到和我一样的问题