【发布时间】:2021-01-05 12:37:49
【问题描述】:
我想使用 MongoDB .NET 驱动程序 (v.2.11) 删除索引。问题是我不想使用索引名称,而是想将其删除,如下所示:https://docs.mongodb.com/manual/tutorial/manage-indexes/ Remove Specific Index 部分 - 提供索引架构。 如何做呢? 现在使用:
MyCollection.Indexes.DropOne("{ _id: 1, somefield: 1 }");
结果:
MongoDB.Driver.MongoCommandException: 'Command dropIndexes failed: index not found with name [{ _id: 1, somefield: 1 }].'
注意: 集合中存在索引。
【问题讨论】:
-
我认为这是不可能的。不确定确切的用例,但您可以遍历索引,找到您所追求的,然后按名称删除它?