2016-12-14 67 views
1

我升級了我的MongoDB-C#驅動程序,但找不到有關如何創建GeoSpatial索引的信息。我看到很多帖子使用collection.EnsureIndex,但我沒有這個可用。 我用以下,其中「collection」是IMongoCollection<>C#MongoDB驅動程序2.4 - 如何添加GeoSpatial索引

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

什麼是新的方式來做到這一點?

回答

1

,我認爲這可以幫助你:

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