[CSHARP-1455] Checking for the existence of an index is very verbose Created: 22/Oct/15  Updated: 08/Feb/23  Resolved: 03/Dec/20

Status: Closed
Project: C# Driver
Component/s: API
Affects Version/s: 2.0, 2.1
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Nick Judson Assignee: Unassigned
Resolution: Won't Fix Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

This is a request for a 'HasIndex(string indexName)' or 'ContainsIndex(string indexName)' helper.

Unless I'm missing something, to find out if an index exists on a collection, one must:

var query = await myCollection.Indexes.ListAsync();
var bsonIndexes = await query.ToListAsync();
var indexNames = bsonIndexes .Select(i => i.Values); // or some variation
return indexNames.Contains("blah");



 Comments   
Comment by Jeffrey Yemin [ 03/Dec/20 ]

If anyone is still interested in this issue, we can re-open and re-consider.

Comment by KevinBrok [ 25/Feb/19 ]

I created another issue similar to this since I found an usecase in which you want to retrieve the existsing Index.

CSHARP-2529

Comment by Donny V [ 07/Jun/16 ]

I think the reason they got rid of IndexExists is because if you try to add an existing index it doesn't do anything. So you don't really need to check if its there anymore. Just add it and Mongo will take care of adding or ignoring the request.

Generated at Wed Feb 07 21:39:39 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.