Hi,
Using the new C# driver (2.0), I'm trying to atomically FindAndModify a document, where an existing sub document with a specific property value doesn't already exist.
Take this model:
{
_id:1,
subdocs: [
{ ref:1,val:'1'},
{ ref:2,ref:'2'}
]
}
I want to $addtoset to subdocs where the a sub document with a ref doesn't already exist.
var filterId = Builders<Organisation>.Filter.Eq(p => p.Id, 1);
var filterNotExist = Builders<Organisation>.Filter.???(*???*);
var filterAnd = Builders<Organisation>.Filter.And(filterId,filterNotExist);
var update = Builders<Organisation>.Update.AddToSet(p => p.Facilities, facility);
return await GetCollection().FindOneAndUpdateAsync(filterAnd, update);
I thought about doing a Not filter on an AnyEq, but unsure of syntax.
To complicate things further how would I do the same for another nested sub document?
Many thanks
Sam