I want to update a collection that contains only some Id and an objectId dictionary for objectId.
public class ME_BlaBla { [BsonId] public ObjectId MyId; public Dictionary<ObjectId, ObjectId> IdsToOtherIds; }
I'm sorry if my names are not informative, I cannot exchange the 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, I'm trying to filter out the MyId
field, but when I want to insert data there, I do not want duplication of any type, not in Keys
or in Values
The whole idea is that the update should be atomic and verify that none of the identifiers provided are in the dictionary.
I'm still trying to figure out how to use the Exists
filter here, so this might be the answer.
TIA.
EDIT
I changed the code to something like this: (still not sure if it works well ... does not test its 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)));
source share