I have a document like this:
{
"_id" : "DummyId",
"in_use" : NumberInt(1),
"host" : "3cec176f-e14e-4fa9-946c-3fc395f8af98",
"locktime" : ISODate("2016-04-06T14:43:00.842+0000"),
"owner" : "DummyOwner",
"readerList" : [
{
"_id" : "3cec176f-e14e-4fa9-946c-3fc395f8af98",
"ts" : ISODate("2016-04-06T14:43:00.843+0000")
},
{
"_id" : "b959ee51-bfa5-4fe2-a9bf-9070e2c8c742",
"ts" : ISODate("2016-04-06T13:36:58.493+0000")
}
],
}
I want to remove from readerList any object which has a specific _id value or which has a ts older than a minute. I'm trying the following code:
List<UpdateDefinition<BsonDocument>> updateList = new List<UpdateDefinition<BsonDocument>>();
updateList.Add(Builders<BsonDocument>.Update.PullFilter("readerList", Builders<BsonDocument>.Filter.Eq("_id", _uniqueId)));
updateList.Add(Builders<BsonDocument>.Update.PullFilter("readerList", Builders<BsonDocument>.Filter.Lt("ts", DateTime.UtcNow.AddMinutes(-1.0))));
update = Builders<BsonDocument>.Update.Combine (updateList);
UpdateResult res = await _syncLockCollection.UpdateOneAsync(filter, update);
What happens is that whichever PullFilter is last gets executed. Is there a way to accomplish this using the C# driver? It's crucial to my design that I be able to accomplish this as a single operation, so I can't fall back on reading the document, making my changes, and writing it again.
Any help would be appreciated!
Brian