I have an object like that:
public class Foo {
public string Id {get;set;}
public List<Bar> Bars {get;set;}
}
public class Bar {
public string Id {get;set;}
public bool Read {get;set;}
}
I would like to update multiple bars basead on a list of bar ids. I am trying to do something like that, but it only updates one record instead of multiple:
public bool MarkAsRead(string fooId, List<string> barIds)
{
var @in = new FilterDefinitionBuilder<Bar>().In(x => x.Id, barIds);
var filter = Filter().Eq(x => x.Id, fooId) & Filter().ElemMatch(x => x.Bars, @in);
var update = UpdateFilter()
.Set(x => x.Bars[-1].Read, true);
var result = collection.UpdateOne(filter, update);
return result.MatchedCount > 0;
}
How can I do that?