public async Task UpdateCollectionsAsync(IOspSession session) { var ckEntities = (await CkEntities.GetAsync(session)).ToList(); foreach (var ckEntity in ckEntities) { var suffix = ckEntity.CkId.Replace(".", "_"); await _repository.CreateCollectionIfNotExistsAsync <RtEntity>(suffix); } }
public async Task UpdateIndexAsync(IOspSession session) { var ckEntities = (await CkEntities.GetAsync(session)).ToList(); foreach (var ckEntity in ckEntities) { string name = ckEntity.CkId.Replace(".", "_"); var collection = GetRtCollection <RtEntity>(ckEntity.CkId); await collection.DropIndexAsync(name); await collection.DropIndexAsync("OspSystem"); } foreach (var ckEntity in ckEntities) { foreach (var index in ckEntity.Indexes) { if (index.IndexType == IndexTypes.None) { continue; } var collection = GetRtCollection <RtEntity>(ckEntity.CkId); string newName = ckEntity.CkId.Replace(".", "_") + "_" + ObjectId.GenerateNewId(); switch (index.IndexType) { case IndexTypes.Ascending: await collection.CreateAscendingIndexAsync(newName, index.Fields.SelectMany(x => x.AttributeNames)); break; case IndexTypes.Text: await collection.CreateTextIndexAsync(newName, index.Language, index.Fields); break; default: throw new NotImplementedException($"Index type {index.IndexType} is not implemented."); } } } }