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,


atleast tell me what are all the posiible ways to achieve that. because people may implement their own logic and its not that efficient. i also faced an issue where once the data is submitted i need to change "status" field to submitted from "in progress" so i it would be better if u people have gave some standard ways to achieve that. and if i dont find some standard ways to achieve i will move to other database .......

kindly gave some examples on this,also how to design a table with such requirements. if u would have gave examples of how to avoid such single field updates thing. then kinvey is really a awesome product to use.......

I also have to say this is one of the most "painful" part to handle with Kinvey's data storage. Furthermore I have to contradict to Damien Bell: It IS possible in MongoDB to update a single column value. See documentation here


Why "painful"? You want to update a single column of collection but you normally don't have the WHOLE record(s) in memory in order to process the full update. So you first have to read the whole record(s) before you update it (more traffic). If I could choose I'd rather would prefer single column updates than single column reads.


Regards


Tayger,

There is no way to update partial data in Kinvey using SDKs or REST APIs. There is no direct method to update a single field of an entity without providing other attributes. But you can try implementing it using old Business Logic using "collectionAccess" and "$set" operator. Check this link for collection access using Business Logic. 


Thanks,

Pranav

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,

Hi Pranav


First of all thank you for forwarding the $nearsphere problem, that is solved now!


Concerning update: I am aware that Kinvey does not support update operation by API functionalities as it's known in MongoDB. Sure it would be nice if it would be supported but the trick with the Business Logic might help! I'm sure I have to do such operations and will check therefore the Business Logic chapter. Can't even wait to look into it (have some other things doing there).

Some years ago the lowest granularity concerning Big Data/NoSQL was on record, no updates where allowed on single columns. An update at that time was deleting the current record (or set it unusable) and add a new one (with the updates in it). The demand for UPDATE by API was then so high that it's now part in most Big Data/NoSQL DBs. So it would have been nice there were an UPDATE command on API level since doing an update on Business Logic level is imho a workaround but for a "simple" update not the right place (if it has nothing to do with the concept of "Business Logic").

As long as there is a solution I'm happy with it!

Regards and thank you

Login or Signup to post a comment