Refresh field in mongodb c # array driver

I am trying to update the status field for an object from a p2l array

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

It seems that the code will work fine, but how to implement it with a typed builder and set all fields with lambda? I found a solution at the following link How to update a field in an array subtask contained in an array subtask in MongoDB using the C # driver?

But it is only suitable for the old driver version.

+5
source share
1 answer

You can try something like:

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

Note -1 is an index for a collection of pets, which means applying a set to all items.
I found this solution by researching UpdateDefinitionBuilderTests .

+8
source

All Articles