I have a Shipment object with a nested list of materials objects (note : _id refers to the shipmentId)
"_id" : "1",
"createddate" : "2018-10-18T16:25:59.245Z",
"attributes" : {
"materials" : [
{
"materialcode" : "string",
"status" : "Unmatched"
}
]
},
I would like to delete the the material of the corresponding shipment if the status = Unmatched. I am trying to use pull or pullfilter just not sure how to use it
here is what I have so far, (this does not build as I get error cannot covert lamda expression to field expression ):
Task<bool> DeleteShipmentMaterials(string ShipmentId, string MaterialId)
{
var shipment = await GetShipment(ShipmentId);
foreach (var material in shipment.attributes.Materials)
{
var update = Builders<Shipment>.Update.PullFilter(x => x.attributes.Materials, Builders<Shipment>.Filter.Eq(x => x.Id, shipment.Id));
.MaterialCode == material.MaterialCode), );
await UpdateOneAsync(c => c.Id == shipment.Id, update, true);
}