public Task InsertManyAsync <T>(List <T> documents) where T : DocumentBase { var collection = CollectionResolver.Get <T>(_database); return(collection.InsertManyAsync(documents)); }
public Task <DeleteResult> DeleteOneAsync <T>(FilterDefinition <T> filter) where T : DocumentBase { var collection = CollectionResolver.Get <T>(_database); return(collection.DeleteOneAsync(filter)); }
public Task InsertOneAsync <T>(T document) where T : DocumentBase { var collection = CollectionResolver.Get <T>(_database); return(collection.InsertOneAsync(document)); }
public Task <DeleteResult> DeleteManyAsync <T>(Expression <Func <T, bool> > filter) where T : DocumentBase { var collection = CollectionResolver.Get <T>(_database); return(collection.DeleteManyAsync(filter)); }
public Task <ReplaceOneResult> ReplaceOneAsync <T>(Expression <Func <T, bool> > filter, T document, UpdateOptions updateOptions = null) where T : DocumentBase { var collection = CollectionResolver.Get <T>(_database); return(collection.ReplaceOneAsync(filter, document, updateOptions)); }
public Task <UpdateResult> UpdateAsync <T>(Expression <Func <T, bool> > filter, UpdateDefinition <T> updateDefinition, UpdateOptions updateOptions = null) where T : DocumentBase { var collection = CollectionResolver.Get <T>(_database); return(collection.UpdateManyAsync(filter, updateDefinition, updateOptions)); }
public async Task <T> FindOneAsync <T>(Expression <Func <T, bool> > filter, FindOptions <T> findOptions = null) where T : DocumentBase { var collection = CollectionResolver.Get <T>(_database); var asyncCursor = await collection.FindAsync(filter, findOptions).ConfigureAwait(false); return(await asyncCursor.SingleOrDefaultAsync().ConfigureAwait(false)); }
public async Task <List <TProjection> > FindAsync <T, TProjection>(Expression <Func <T, bool> > filter, FindOptions <T, TProjection> findOptions = null) where T : DocumentBase { var collection = CollectionResolver.Get <T>(_database); IAsyncCursor <TProjection> asyncCursor = await collection.FindAsync(filter, findOptions).ConfigureAwait(false); return(await asyncCursor.ToListAsync().ConfigureAwait(false)); }
public static Task CreateIndexAsync(IMongoDatabase database) { var keys = Builders <TeamDocument> .IndexKeys.Ascending(t => t.Id); var model = new CreateIndexModel <TeamDocument>(keys); var collection = CollectionResolver.Get <TeamDocument>(database); collection.Indexes.CreateOne(model); return(collection.Indexes.CreateOneAsync(model)); }
public Task <DeleteResult> DeleteManyAsync <T>(FilterDefinition <T> filter = null) where T : DocumentBase { if (filter == null) { // empty filter to delete all filter = new BsonDocumentFilterDefinition <T>(new MongoDB.Bson.BsonDocument()); } var collection = CollectionResolver.Get <T>(_database); return(collection.DeleteManyAsync(filter)); }
public Task <UpdateResult> UpdateAsync <T>(UpdateDefinition <T> updateDefinition, FilterDefinition <T> filter = null, UpdateOptions updateOptions = null) where T : DocumentBase { if (filter == null) { //empty filter filter = new BsonDocumentFilterDefinition <T>(new BsonDocument()); } var collection = CollectionResolver.Get <T>(_database); return(collection.UpdateManyAsync(filter, updateDefinition, updateOptions)); }
public async Task <T> FindOneAsync <T>(FilterDefinition <T> filter = null, FindOptions <T> findOptions = null) where T : DocumentBase { var collection = CollectionResolver.Get <T>(_database); if (filter == null) { // provide empty filter to fetch all filter = new BsonDocumentFilterDefinition <T>(new MongoDB.Bson.BsonDocument()); } var asyncCursor = await collection.FindAsync(filter, findOptions).ConfigureAwait(false); return(await asyncCursor.SingleOrDefaultAsync().ConfigureAwait(false)); }
public async Task <List <TProjection> > FindAsync <T, TProjection>(FilterDefinition <T> filter = null, FindOptions <T, TProjection> findOptions = null) where T : DocumentBase { var collection = CollectionResolver.Get <T>(_database); if (filter == null) { //empty filter filter = new BsonDocumentFilterDefinition <T>(new BsonDocument()); } IAsyncCursor <TProjection> asyncCursor = await collection.FindAsync(filter, findOptions).ConfigureAwait(false); return(await asyncCursor.ToListAsync().ConfigureAwait(false)); }
public static Task CreateIndexAsync(IMongoDatabase database) { // compound index var keys = Builders <UpdateLogDocument> .IndexKeys .Ascending(t => t.Week) .Ascending(t => t.Season); var options = new CreateIndexOptions { Unique = true }; var model = new CreateIndexModel <UpdateLogDocument>(keys, options); var collection = CollectionResolver.Get <UpdateLogDocument>(database); return(collection.Indexes.CreateOneAsync(model)); }
public static Task CreateIndexAsync(IMongoDatabase database) { var keys = Builders <WeekMatchupDocument> .IndexKeys .Ascending(t => t.HomeTeamId) .Ascending(t => t.AwayTeamId) .Ascending(t => t.Week) .Ascending(t => t.Season); var options = new CreateIndexOptions { Unique = true }; var model = new CreateIndexModel <WeekMatchupDocument>(keys); var collection = CollectionResolver.Get <WeekMatchupDocument>(database); collection.Indexes.CreateOne(model); return(collection.Indexes.CreateOneAsync(model)); }
private Task <IAsyncCursor <T> > FindWithCursorAsync <T>(FilterDefinition <T> filter = null, FindOptions <T> findOptions = null) where T : DocumentBase { var collection = CollectionResolver.Get <T>(_database); if (filter == null) { // provide empty filter to fetch all filter = new BsonDocumentFilterDefinition <T>(new MongoDB.Bson.BsonDocument()); } if (findOptions == null) { findOptions = new FindOptions <T> { NoCursorTimeout = true }; } return(collection.FindAsync(filter, findOptions)); }