コード例 #1
0
        public async Task <User> GetUser(string username, string password)
        {
            var collection = _mongo.GetCollection <User>();
            var users      = collection.Find <User>(user => user.Username == username && user.Password == password);

            return(await users.FirstAsync());
        }
コード例 #2
0
        public async Task <IEnumerable <Comment> > GetAllComments()
        {
            var collection = _mongo.GetCollection <Comment>();
            var comments   = collection.Find <Comment>(_ => true);

            return(await comments.ToListAsync());
        }
コード例 #3
0
 public async Task UpsertDocumentAsync <T>(Expression <Func <T, bool> > filter, T document) where T : class
 {
     var collection = _mongo.GetCollection <T>();
     await collection.ReplaceOneAsync(filter, document, new UpdateOptions { IsUpsert = true });
 }