简体   繁体   English

更新数组mongodb c#driver中的字段

[英]Update field in array mongodb c# driver

I try to update status field for object from p2l array 我尝试从p2l数组更新对象的status字段

var update = Builders<BsonDocument>.Update.Set("p2l.$.status",BsonValue.Create(status))

It seems that code will work fine, but how to implement it with typed builder and set all fields with lambda ? 似乎代码可以正常工作,但如何使用类型化构建器实现它并使用lambda设置所有字段? I found a solution by the following link How to update a field in an array's subdocument contained in an array's subdocument in MongoDB using C# driver? 我通过以下链接找到了解决方案如何使用C#驱动程序更新MongoDB中数组子文档中包含的数组子文档中的字段?

But it suitable only for old version of driver. 但它仅适用于旧版本的驱动程序。

You can try something like: 您可以尝试以下方式:

Builders<Person>.Update.Set(x => x.Pets[-1].Name, "Fluffencutters")

Note -1 index on Pets collection, that means to apply set for all elements. 注意-1 Pets上的索引,表示为所有元素应用set。
I found this solution by exploring UpdateDefinitionBuilderTests . 我通过探索UpdateDefinitionBuilderTests找到了这个解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MongoDB 驱动程序 C# 更新嵌套对象数组中的单个字段 - MongoDB Driver C# Update a single field in Nested Array of Objects Mongodb C#驱动程序更新数组元素 - Mongodb C# driver update array element 如何使用C#驱动程序更新MongoDB中数组子文档中包含的数组子文档中的字段? - How to update a field in an array's subdocument contained in an array's subdocument in MongoDB using C# driver? 使用 C# 驱动程序更新 MongoDb 中数组数组内的字段 - Update a field which is inside array of array in MongoDb using C# driver 如何使用 Mongodb c# 驱动程序更新文档的数组字段的特定索引值? - How to update document's array field's specific indexed value using Mongodb c# driver? 如何使用 C# MongoDb 驱动程序更新深度嵌套数组中的“类型安全”字段? - How to update a field “type-safe” in a deeply nested array with C# MongoDb driver? 使用 MongoDB C# 驱动程序更新列表中的字段 - Update field inside the list using MongoDB C# driver MongoDb c#driver按字段值查找数组中的项目 - MongoDb c# driver find item in array by field value 如何在 C# 的 MongoDB 驱动程序中获取数组中一个字段的值 - How to get values of one field in array in MongoDB Driver for C# MongoDB C# 驱动程序 - 更新嵌入文档数组中的所有字段 - MongoDB C# Driver - update all fields in embedded array of documents
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM