I want to update a collection which only contains some Id and a dictionary of objectId to objectId.
public class ME_BlaBla
{
[BsonId]
public ObjectId MyId;
public Dictionary<ObjectId, ObjectId> IdsToOtherIds;
}
Im sorry if my names aren't informative, I can't share real code =.
Now, I have this query:
var filter = Builders<ME_BlaBla>.Filter.And(
Builders<ME_BlaBla>.Filter.Eq(t => t.MyId, id),
Builders<ME_BlaBla>.Filter.Not(Builders<ME_BlaBla>.Filter.Exists(t => t.IdsToOtherIds.Values, valueId)),
Builders<ME_BlaBla>.Filter.Not(Builders<ME_BlaBla>.Filter.Exists(t => t.IdsToOtherIds.Keys, keyId)));
So, Im trying to filter by the MyId
field but when I want to insert data to there I don't want duplication of any kind, Not in the Keys
nor in the Values
The whole idea is that the updating must be atomic and check that neither of the provided ids are contained in the dictionary.
I'm still trying to understand how to use the Exists
filter here, so it might be the answer.
TIA.
EDIT
I changed the code to something like that: (still not sure its working well..cannot test it atm)
Builders<ME_BlaBla>.Filter.Not(Builders<ME_BlaBla>.Filter.ElemMatch(t => t.IdsToOtherIds, a => a.Key == keyId)),
Builders<ME_BlaBla>.Filter.Not(Builders<ME_BlaBla>.Filter.ElemMatch(t => t.IdsToOtherIds, a => a.Value == valueId)));