使用CSharp更新子文档

时间:2014-04-19 04:47:28

标签: c# mongodb mongodb-.net-driver

您好任何人都可以告诉我如何更新Mongo Document中的子子。我尝试了以下查询

var UpdateInvoice = Update.Set("Paid.Invoice.$.Number", 123456)
    .Set("Paid.Invoice.$.Amount", 200)
    .Set("Paid.Invoice.$.SubscriptionPeriod", 20)
    .Set("Paid.Invoice.$.Date", DateTime.Now)
    .Set("Paid.Invoice.$.UserCount", 10)
    .Set("Paid.Invoice.$.ProjectCount", 5);
var queryUpdateInvoice = collection.Update(
    Query.And(
        Query.EQ("_id", "5350ceb26699c2180856a42a"),
        Query.EQ("_id", "5350af0f6699c2115c8495a4"),
        Query.ElemMatch("Invoice", Query.EQ("_id", "5350cefe6699c21bd8554f21"))
    ),
    UpdateInvoice, UpdateFlags.Upsert
);

在上面的代码中,Paid是子项,发票是子项。上面的查询对我没有用。查询部分中的ID是文档的ID,付费,发票。请帮助我,因为我无法找到更新文档的替代方法

public class Paid
    {
        [BsonId]
        public string Id { get; set; }
        public List<Invoice> Invoice = new List<Invoice>();
        public string Status { get; set; }
}
public class Invoice
    {
        [BsonId]
        public string Id { get; set; }
        public long Number { get; set; }
        public int UserCount { get; set; }
}

这些是我的课程,付费和发票是同一份文件。我想要更新文件中的Invocie部分付费

0 个答案:

没有答案