Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#MongoDB驱动程序2.4-如何添加地理空间索引_C#_Mongodb_Indexing_Geospatial_Mongodb .net Driver - Fatal编程技术网

C#MongoDB驱动程序2.4-如何添加地理空间索引

C#MongoDB驱动程序2.4-如何添加地理空间索引,c#,mongodb,indexing,geospatial,mongodb-.net-driver,C#,Mongodb,Indexing,Geospatial,Mongodb .net Driver,我升级了MongoDB-C驱动程序,但找不到有关如何创建地理空间索引的信息。我看到很多帖子都使用了collection.EnsureIndex,但我没有这一功能。 我曾经使用过以下命令,其中“collection”是IMongoCollection: 做这件事的新方法是什么?我认为这可以帮助您: var index = Builders<YourCollectionClass>.IndexKeys.Geo2DSphere("Location"); collection.Indexes

我升级了MongoDB-C驱动程序,但找不到有关如何创建地理空间索引的信息。我看到很多帖子都使用了
collection.EnsureIndex
,但我没有这一功能。 我曾经使用过以下命令,其中“
collection
”是
IMongoCollection


做这件事的新方法是什么?

我认为这可以帮助您:

var index = Builders<YourCollectionClass>.IndexKeys.Geo2DSphere("Location");
collection.Indexes.CreateOne(index);
// or async version
await collection.Indexes.CreateOneAsync(index);
var index=Builders.IndexKeys.Geo2DSphere(“位置”);
collection.index.CreateOne(索引);
//或异步版本
等待collection.index.CreateOneAsync(索引);
var index = Builders<YourCollectionClass>.IndexKeys.Geo2DSphere("Location");
collection.Indexes.CreateOne(index);
// or async version
await collection.Indexes.CreateOneAsync(index);