dj-nitehawk / MongoDB.Entities

A data access library for MongoDB with an elegant api, LINQ support and built-in entity relationship management
https://mongodb-entities.com
MIT License
543 stars 69 forks source link

which index will .Option apply on? #181

Closed li-zheng-hao closed 2 years ago

li-zheng-hao commented 2 years ago
 DB.Index<Model>()
   .Key(it => it.A, KeyType.Ascending)
   .Key(it => it.B, KeyType.Ascending)
   .Option(o => { o.Unique = true; })
   .CreateAsync();

hello i just started using this library,in the above case,will unique attribute apply on A or B or Both?

dj-nitehawk commented 2 years ago

specify index keys by chaining calls to the .Key() method. compound indexes are created by calling the .Key() method multiple times.

so when you call .Key() multiple times, you're creating a compound index. so the uniqueness applies to the compound index as a whole.

to create single key indexes, just call .Key() once per each .CreateAsync() call.