コード例 #1
0
        public Task InsertManyAsync <T>(List <T> documents)
            where T : DocumentBase
        {
            var collection = CollectionResolver.Get <T>(_database);

            return(collection.InsertManyAsync(documents));
        }
コード例 #2
0
        public Task <DeleteResult> DeleteOneAsync <T>(FilterDefinition <T> filter)
            where T : DocumentBase
        {
            var collection = CollectionResolver.Get <T>(_database);

            return(collection.DeleteOneAsync(filter));
        }
コード例 #3
0
        public Task InsertOneAsync <T>(T document)
            where T : DocumentBase
        {
            var collection = CollectionResolver.Get <T>(_database);

            return(collection.InsertOneAsync(document));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #9
0
ファイル: TeamDocument.cs プロジェクト: zaawilli/FFDB
        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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #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));
        }
コード例 #14
0
ファイル: UpdateLogDocument.cs プロジェクト: zaawilli/FFDB
        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));
        }
コード例 #15
0
ファイル: WeekMatchupDocument.cs プロジェクト: zaawilli/FFDB
        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));
        }
コード例 #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));
        }