Start a new topic
Answered

How to update only selected filed?

Kinvey.DataStore.update will override the whole record, not only update selected fields. What is the difference between Kinvey.DataStore.update and Kinvey.DataStore.save? How do I update only selected fields?


Best Answer

Daniel,


We appreciate the feedback, however the feature that you're asking to do (update a single field) maps well to MySQL, but goes both against REST and Mongo standards.   We allow users to query on specific fields with the understanding that the item they receive from these queries should be used for read-only purposes.  As such, we encourage and gear our documentation towards dealing with whole objects rather than partial ones.   


If you see any areas where our documentation can improve specifically, please contact me directly and I will work to get them up to snuff.


Thanks,


Daniel,


This isn't possible unfortunately as it would deviate from how Mongo stores objects and would go against our RESTful paradigm.   The proper way to update a field is to grab the entire object, modify the fields you want and save / update it back to Kinvey.


To the other question:  The difference between Save / Update is that save will create the item if it doesn't yet exist, whereas update will not, and will throw an error.


Please let me know if you have any other questions,

Hi Damien


this is what your documentation says:


<static> update(collection, document, options) → {Promise}

Updates an existing document. If the document does not exist, however, it is created.


Daniel,


I actually didn't check the documentation, I spoke with the library owner, let me follow up with him and see if the documentation is out of date or if he misspoke.


Thanks,


Actually it does not matter if new object is created or not, the whole update function is pretty useless the way it is implemented. You should at least consider updating the documentation so that people won't waste their time trying to implement it. 

Answer

Daniel,


We appreciate the feedback, however the feature that you're asking to do (update a single field) maps well to MySQL, but goes both against REST and Mongo standards.   We allow users to query on specific fields with the understanding that the item they receive from these queries should be used for read-only purposes.  As such, we encourage and gear our documentation towards dealing with whole objects rather than partial ones.   


If you see any areas where our documentation can improve specifically, please contact me directly and I will work to get them up to snuff.


Thanks,

Login or Signup to post a comment