【发布时间】:2018-11-16 13:26:30
【问题描述】:
我正在使用官方 C# MongoDb 强类型驱动程序版本 2.7.0-beta001 在 Windows 10 机器上与 MongoDB v 4.0-rc1 进行交互。
考虑以下类:
public class Library
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public DateTime DateAdded { get; set; }
public DateTime LastModified { get; set; }
public string Title { get; set; }
public Author Author { get; set; }
public bool AllBooks { get; set; }
}
public class Author {
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string BirthDate { get; set; }
public string ScientificDegree { get; set; }
public List<Book> Books { get; set; }
}
public class Book
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public string Title { get; set; }
public int PublishYear { get; set; }
public string Content { get; set; }
public bool IsVerified { get; set; }
}
如果所有作者的书籍都经过验证,如何更新图书馆文档,这是我的代码:
string libraryId = GetLibraryId();
var repository = _database.GetCollection<Library>("Libraries");
var filter = Builders<Library>.Filter.Where(l => l.Id == libraryId &&
l.Author.Books.All(b => b.IsVerified == true));
var update = Builders<Library>.Update.Set(l => l.AllBooks, true);
await repository.UpdateOneAsync(filter, update);
最后一行抛出 System.ArgumentException: Unsupported filter: All
【问题讨论】:
标签: c# .net mongodb mongodb-query mongodb-.net-driver