Skip to content

Commit

Permalink
feat : add index crud methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikoo-Asadnejad committed Aug 2, 2023
1 parent 4168913 commit 114adf8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,12 @@ Task<List<TProjected>> FilterByAsync<TProjected>(
Task<bool> IsExist(Expression<Func<TDocument, bool>> query);
Task<bool> IsExist(string id);
void DropCollection();
Task RenameCollectionAsync(string newName);
Task DropAllIndexesAsync();
Task DropIndexAsync(string indexName);
Task CreateIndexAsync(string indexName, CreateIndexOptions options = null);
Task CreateIndexesAsync(IEnumerable<CreateIndexModel<TDocument>> models);
Task CreateIndexesAsync(Dictionary<string, CreateIndexOptions<TDocument>> keyOptions);
Task GetIndexListAsync(IEnumerable<string> keynames);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,33 @@ public void DropCollection()

public async Task RenameCollectionAsync(string newName)
=> await _database.RenameCollectionAsync(_collectionName ,newName);

public async Task DropAllIndexesAsync()
=> await _collection.Indexes.DropAllAsync();



public async Task DropIndexAsync(string indexName)
=> await _collection.Indexes.DropOneAsync(indexName);

public async Task CreateIndexAsync(string indexName , CreateIndexOptions options = null)
=> await _collection.Indexes.CreateOneAsync(indexName, options);

public async Task CreateIndexesAsync(IEnumerable< CreateIndexModel<TDocument>> models)
=> await _collection.Indexes.CreateManyAsync(models);

public async Task CreateIndexesAsync(Dictionary<string,CreateIndexOptions<TDocument>> keyOptions)
{
List<CreateIndexModel<TDocument>> models = new ();
foreach (var keyOption in keyOptions)
{
models.Add(new CreateIndexModel<TDocument>(keyOption.Key ,keyOption.Value));
}

await _collection.Indexes.CreateManyAsync(models);
}

public async Task GetIndexListAsync(IEnumerable<string> keynames)
=> await _collection.Indexes.ListAsync();


}
}

0 comments on commit 114adf8

Please sign in to comment.