Start a new topic

How to update a row in existing collection?

Hello, I am new Kinvey User. I am using kinvey for developing android apps. I have to update or edit a row in to my existing collection.. so plz help how can i impliment this..


Sukhpal,


You would need to call save after doing the update to the entity in the database, but otherwise, yes, this is correct.

Sukhpal,


From the guide I linked above:


  

EventEntity event = new EventEntity();
event.setName("Launch Party");
event.setAddress("Kinvey HQ");
AsyncAppData<EventEntity> myevents = mKinveyClient.appData("events", EventEntity.class);
myevents.save(event, new KinveyClientCallback<EventEntity>() {
    @Override
    public void onFailure(Throwable e) {
        Log.e("TAG", "failed to save event data", e); 
    }
    @Override
    public void onSuccess(EventEntity r) {
        Log.d("TAG", "saved data for entity "+ r.getName()); 
    }
});

 


To fetch the saved object (by id -- which would be in the fileMetaData object)


 

EventEntity event = new EventEntity();
AsyncAppData<EventEntity> myEvents = mKinveyClient.appData("events", EventEntity.class);
myEvents.getEntity(eventID, new KinveyClientCallback<EventEntity>() {
    @Override
    public void onSuccess(EventEntity result) { 
        Log.v("TAG", "received "+ result.getId() );
    }
    @Override
    public void onFailure(Throwable error) { 
        Log.e("TAG", "failed to fetchByFilterCriteria", error);
    }
});

 


Please let me know if you have any other questions.


Thanks, 








Can i update the object after fetching inside the onSuccess method using objectName.setValue();


like this: 


EventEntity events = new EventEntity();

Query myQuery = mKinveyClient.query();myQuery.equals("Name","LaunchParty");

AsyncAppData<EventEntity> myEvents = mKinveyClient.appData("events",EventEntity.class);


myEvents.get(myQuery, new KinveyListCallback<EventEntity>() { 


@Override public void onSuccess(EventEntity[] results) { 


results.setName("Celebration Party");


Log.v("TAG", "received "+ results.length + " events"); 


} 


@Override public void onFailure(Throwable error) { 


Log.e("TAG", "failed to fetchByFilterCriteria", error); 


}


});

please provide me a simple code .. it will be helpful for me.. thnks


Good morning Sukhpal,  


It seems as though you are thinking about things in a relational database (MySQL specifically) sort of way.   MySQL thinks about "rows" and "columns" of data, an update seeks to find a specific row or set of rows, and then update a specific column within that row.


Kinvey's backends run on MongoDB, which is considerably different from MySQL.  There are no rows and columns, only objects.   The data-browser in the console displays objects as rows and columns which can be a bit misleading as it makes people think about things in a MySQL sort of way.    Where mongo only cares about entire objects, we recommend that you grab the entire object, change the parts of the object that you want to be updated, and then write the entire object back to Kinvey.   There are ways within Mongo to update certain fields, but the majority of our libraries do not expose these functions to the end user, as it is extremely easy to accidentally modify your data-structure by incorrectly updating a single field within a collection, which could create a great deal of issues elsewhere in your application.


With that said, our SDK's are created in a way to work with whole-objects which is what that guide goes into.


Is there a use case where doing it this way wouldn't accomplish the goals that you are trying to accomplish?  If so could you please explain your use case to me?   


Thanks,

Thanks Damien Bell,


I want to update FirstName and LastName by _id  of a particular row. In the datastore user guide i can't understand .. plz give me some explanation of the code how can i implement..


I wanna like query : "Update FirstName and LastName where Email = 'abc@example.com' ";

Hello there Sukhpal,


If you take a peek over in our datastore guide you can see an outline to your answer here:


http://devcenter.kinvey.com/android/guides/datastore#Saving


Please let me know if you have any other questions,

Login or Signup to post a comment