/// <summary> /// Creates the indexes. /// </summary> private void CreateIndexes(Database database) { foreach (var rootClassMap in this.mappingStore.RootClassMaps) { //getting a collection is more expensive than counting indexes, so let's make this as fast as possible... if (rootClassMap.Indexes.Count() == 0) continue; var collectionMetaData = database.GetCollection(rootClassMap.CollectionName).MetaData; foreach (var index in rootClassMap.Indexes) { Document fieldsAndDirections = new Document(); foreach (var part in index.Parts) { fieldsAndDirections.Add( part.Key, part.Value == IndexDirection.Ascending ? 1 : -1); } collectionMetaData.CreateIndex(index.Name, fieldsAndDirections, index.IsUnique); } } }