Exemplo n.º 1
0
        public Task InsertManyAsync <T>(List <T> documents)
            where T : DocumentBase
        {
            var collection = CollectionResolver.Get <T>(_database);

            return(collection.InsertManyAsync(documents));
        }
Exemplo n.º 2
0
        public Task <DeleteResult> DeleteOneAsync <T>(FilterDefinition <T> filter)
            where T : DocumentBase
        {
            var collection = CollectionResolver.Get <T>(_database);

            return(collection.DeleteOneAsync(filter));
        }
Exemplo n.º 3
0
        public Task InsertOneAsync <T>(T document)
            where T : DocumentBase
        {
            var collection = CollectionResolver.Get <T>(_database);

            return(collection.InsertOneAsync(document));
        }
Exemplo n.º 4
0
        public Task <DeleteResult> DeleteManyAsync <T>(Expression <Func <T, bool> > filter)
            where T : DocumentBase
        {
            var collection = CollectionResolver.Get <T>(_database);

            return(collection.DeleteManyAsync(filter));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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));
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
        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));
        }
Exemplo n.º 11
0
        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));
        }
Exemplo n.º 12
0
        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));
        }
Exemplo n.º 13
0
        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));
        }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
        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));
        }
Exemplo n.º 16
0
        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));
        }