Add index for list/object in .Net driver

Hi,
In MongoDB profiler I see that we have unindexed collection that causes bad performance.
As you can see here:

I want to avoid this.
What is the syntax for creating indexes for that collection, so this query will be more effective?
(My question is how to add index for ‘Entity.Airports.SearchName’ in C#? ‘Airports’ is a list of objects)

Hi, @Reut_Shaul,

You can create new indexes using the index management API provided by the driver. Indexes can be specified as a JSON string, BsonDocument, or through a fluent builder.

Note that we do not recommend verifying the existence of indexes before every operation as this requires a collection lock on the server. Index creation should be done as part of your installation/deployment script or during application bootstrapping.

Sincerely,
James

1 Like