我需要执行原子“如果不存在添加”逻辑,否则什么都不做,为此我使用 Upsert。我的型号: public class Person { [BsonId] public Guid Id { get; set; } public string Name { get; set; } public string Title { get; set; } public DateTime ReceivedAt { get; set; } public List<Person> Children { get; set; } }我的代码:var person = new Person() { Id = Guid.NewGuid(), Name = "name", Title = "title", ReceivedAt = DateTime.Now };var result = context.People.FindOneAndUpdateAsync<Person>( x => x.Title == person.Title && x.Name == person.Name && x.ReceivedAt <= person.ReceivedAt + TimeSpan.FromMinutes(1), Builders<Person>.Update.Combine(), new FindOneAndUpdateOptions<Person>() { IsUpsert = true });上面是不是插入文件不存在,我做错了什么?我需要设置 IsUpsert 以外的东西吗?
1 回答
- 1 回答
- 0 关注
- 160 浏览
添加回答
举报
0/150
提交
取消