private static async void Update() { //User u = new User() { Name = "xiaopangu", Age = 22, UserID = 1 }; //var filter = Builders<User>.Filter.Eq(u=>u.UserID, 1); //var filter = Builders<User>.Filter.Where(u => u.UserID == 1); //var update = Builders<User>.Update.Set(u => u.Name, "xiaopangu"); User u = new User() { UserID = 2, Age = 111, Name = "xiaopangu2", Id = new ObjectId("56213446f8a4413d38eb5ebd") }; await db.UpdateAsync<User>("user", e => e.UserID == 2, u); //await db.UpdateAsync<User>("user", u); Console.WriteLine("Update successfully"); //await db.GetCollection<User>("user").UpdateOneAsync(filter, update); //await db.UpdateOneAysnc<User>("user", u => u.UserID, 1, "name", "xiaopangu"); }
private static async void Test() { //var projection = Builders<User>.Projection.Expression(u => new { name = u.Name }); //var list = db.GetCollection<User>("user").Aggregate().Match(u => u.Name == "xiaopotian").ForEachAsync(u => { Console.WriteLine(u.Name); }); //db.GetCollection<User>("user").UpdateOneAsync<User>(u=>u.Name=="xiaopotian",MongoQueryable<User>) //User entity = await db.GetCollection<User>("user").Find(u => u.Name == "xiaopotian").FirstOrDefaultAsync(); //entity.Name = "xiaopangu"; User uu = new User { Name = "xiaopangu", Age = 22, UserID = 1 }; await db.GetCollection<User>("user").ReplaceOneAsync<User>(u => u.Name == "xiaopangu", uu); }