Remove a key from Documents

0 votes
Hi All

Lets say I get all users from storage service whose "Coin"=100 by using FindDocumentsByQuery() api. Then I get a list. Then I want to remove just "Coin" key from all of these documents. Other keys will be ramin same. What is the way of doing it? There should be an easy to use api maybe called RemoveKeyFromDocument(). So which api should I use? If I use AddOrUpdateKey, I have to pass complete json again.

Update: If only way is using AddOrUpdateKey, I should somehow remove key from simpleJson. Then I should get Dictionary from that json. But I could not remove and get dictionary from simplejson. Can you please write the code snippet to both remove and convert from json to dictionary?

Thanks
asked May 23, 2016 in Unity by gokhan (20 points)
edited May 23, 2016 by gokhan
I am going to freak out. Please help!!!

JSONObject obj=new JSONObject(jsonDocList[i].GetJsonDoc());
obj.RemoveField("Coin");
storageService.AddOrUpdateKeys("XXX", "YYY",jsonDocList[i].GetDocId(),obj.ToString(),new DeleteCoinKeyCallBack());

I am writing this code but it does not remove "Coin" key. Please help!!!
I found my answer at the end. If someone wants to remove a key, you should use UpdateDocumentByDocId() function.

1 Answer

0 votes

Hi Gokhan,

Apologies for getting late back to you.

Using the UpdateDocumentByDocId method, you need to pass the whole JSON document in method call. However by calling the AddOrUpdateKeys method, you have to pass only those values which need to be updated. So if we understood your requirement than yes, updateDocumentByDocId or updateDocumentByKeyValue function fulfill your objective.

If you need any help from our side, please let us know.

We are happy to assist you!!!

regards,

Himanshu Sharma

 

answered May 24, 2016 by hs00105 (2,005 points)
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...