Code Snippet - How to Add Index to Document at MongoDB C#

2014/3/1·1 min read
// add index to document's field
collection.CreateIndex(IndexKeys.Ascending(_ => _.FieldName));
// add index to subdocument's field
collection.CreateIndex("SubDocument.FieldName");