【问题标题】:C# MongoDB driver 2.4 - How to add a GeoSpatial indexC# MongoDB 驱动程序 2.4 - 如何添加地理空间索引
【发布时间】:2016-12-14 01:20:59
【问题描述】:

我升级了 MongoDB-C# 驱动程序,但找不到有关如何创建 GeoSpatial 索引的信息。我看过很多使用collection.EnsureIndex 的帖子,但我没有那个。 我曾经使用以下内容,其中'collection'是IMongoCollection<>

collection.CreateIndex((new IndexKeysBuilder().GeoSpatialSpherical("Location")));

有什么新方法可以做到这一点?

【问题讨论】:

    标签: c# mongodb indexing geospatial mongodb-.net-driver


    【解决方案1】:

    我认为这可以帮助你:

    var index = Builders<YourCollectionClass>.IndexKeys.Geo2DSphere("Location");
    collection.Indexes.CreateOne(index);
    // or async version
    await collection.Indexes.CreateOneAsync(index);
    

    【讨论】:

      猜你喜欢
      • 2014-01-04
      • 1970-01-01
      • 2011-10-23
      • 1970-01-01
      • 2018-12-17
      • 1970-01-01
      • 2013-07-06
      • 2016-02-12
      • 1970-01-01
      相关资源
      最近更新 更多