I can not seem (despite lots of searching) to find any help with deleting a key from a Realm dictionary (along with value) with the .NET Realm SDK. What I have managed is to delete the value using realm.Remove(), but it leaves a key with the value as null in the Realm collection. What I am currently doing …
var dict = realm.All<my_dict>();
var my_val = dict[my_key];
which leaves the key still in the dictionary, and I would also like the key removed. I feel a little silly, like it is staring me in the face! The closest I could find searching was the $unset keyword, but do not see an equivalent in the .NET Realm SDK.
Thanks in advance for helping me with this silly question!
You can call dict.Remove(my_key). If the value of the dictionary is an object (as it seems to be in your case), that’ll not delete the object from the Realm, just from the dictionary. If you want to remove it both from the dictionary and the Realm, you can either do something like:
var val = dict[my_key];
Thanks for the prompt response, doing dict.Remove(my_key) worked fine. I am using embedded objects, and the embedded object and key were removed from the dictionary. I knew this answer was simple! Thanks again! Josh