【发布时间】:2018-04-12 06:16:36
【问题描述】:
我正在使用官方的 C# MongoDb 强类型驱动程序 2.5.0 版本与 MongoDB 进行交互。
考虑以下类:
public class Author
{
public 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 Library Library { get; set; }
}
public class Library
{
public DateTime DateAdded { get; set; }
public DateTime LastModified { get; set; }
public List<Book> Books { get; set; }
[BsonDefaultValue(0)]
public int ReadCount { get; set; }
}
如何使用作者库中的 id 删除一本书?这是我直接从数组中删除元素的代码。
var field = new ExpressionFieldDefinition<Library, List<Book>>(library => library.Books);
var bookFilter = Builders<Book>.Filter.Eq(book => book.Id, bookId);
var update = Builders<Library>.Update.PullFilter(field, bookFilter);
//How to apply the update to the author using author id
【问题讨论】:
标签: c# .net mongodb mongodb-query mongodb-.net-driver