コード例 #1
0
        internal static async Task <Try <TDocument> > SingleOrDefault <TDocument>(
            this MongoConnection @this,
            Expression <Func <TDocument, bool> > predicate)
            where TDocument : class, IDocument, new()
        {
            try
            {
                var document = await @this
                               .GetCollection <TDocument>()
                               .Find(predicate)
                               .SingleOrDefaultAsync();

                if (document == null)
                {
                    return(new NullObjectException("Document is null."));
                }

                return(document);
            }
            catch (Exception exception)
            {
                return(new InternalException("Could not run command in Mongo.", exception));
            }
        }
コード例 #2
0
 internal static Task AddRange <TDocument>(
     this MongoConnection @this,
     IEnumerable <TDocument> collection)
     where TDocument : class, IDocument, new() => @this
 .GetCollection <TDocument>()
 .InsertManyAsync(collection);
コード例 #3
0
 internal static Task Add <TDocument>(
     this MongoConnection @this,
     TDocument item)
     where TDocument : class, IDocument, new() => @this
 .GetCollection <TDocument>()
 .InsertOneAsync(item);
コード例 #4
0
 internal static Task RemoveAll <TDocument>(
     this MongoConnection @this,
     Expression <Func <TDocument, bool> > predicate)
     where TDocument : class, IDocument, new() => @this
 .GetCollection <TDocument>()
 .DeleteManyAsync(predicate);
コード例 #5
0
 internal static async Task <IReadOnlyCollection <TDocument> > All <TDocument>(
     this MongoConnection @this)
     where TDocument : class, IDocument, new() => await @this
 .GetCollection <TDocument>()
 .Find(Builders <TDocument> .Filter.Empty)
 .ToListAsync();