Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB C# Driver -- Create Index

I am using the MongoDB C# driver to create an index

When my app starts up, it creates the index as below

await collection.Indexes.CreateOneAsync(new BsonDocument("code", 1), new CreateIndexOptions() { Unique = true, Sparse = true });

My question is this: If the index already exists, the index will not be re-created/indexed again, correct?

like image 212
Mr.Wang from Next Door Avatar asked Sep 01 '15 06:09

Mr.Wang from Next Door


People also ask

Does MongoDB use C++?

You can add the driver to your application to work with MongoDB using the C++11 or later standard.

Can you use MongoDB with C#?

By developing with C# and MongoDB together one opens up a world of possibilities. Console, window, and web applications are all possible. As are cross-platform mobile applications using the Xamarin framework.

What is a MongoDB driver?

The official MongoDB Node. js driver allows Node. js applications to connect to MongoDB and work with data. The driver features an asynchronous API which allows you to interact with MongoDB using Promises or via traditional callbacks.


1 Answers

Yes.

As long as the parameters don't change (e.g "code" becomes "Code" or Sparse becomes false) the index will not be recreated and the operation will be a no-op.

like image 103
i3arnon Avatar answered Sep 25 '22 04:09

i3arnon