As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
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,
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' ";
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,
please provide me a simple code .. it will be helpful for me.. thnks
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);
}
});
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,
Sukhpal,
You would need to call save after doing the update to the entity in the database, but otherwise, yes, this is correct.
Thanx Bell, but this is not working for me.. whenever i fetch the entity by _id .. it return a Object of the entity with records but not set the values .. and when i call the save method it add a new row in the database.. please help.
Thanks,
Sukhpal Singh
please provide me a sample of this type if you have..
Can you show me your code? That should not be happening.
Thanks,
private void updateUserDetail() { LoginEntity userEntity = new LoginEntity(); AsyncAppData<LoginEntity> myData = kinveyClient.appData("LoginMaster", LoginEntity.class); myData.getEntity(id, new KinveyClientCallback<LoginEntity>() { @Override public void onSuccess(LoginEntity user) { user.setFirstName(et_firstname.getText().toString()); user.setLastName(et_lastname.getText().toString()); user.setEmail(et_Email.getText().toString()); user.setUsername(et_Username.getText().toString()); user.setRole(spr_Role.getSelectedItem().toString()); user.setProjectName(spr_Projects.getSelectedItem().toString()); Log.v(TAG, "received "+ user.getEmail()); } @Override public void onFailure(Throwable error) { Log.e(TAG, "failed to fetchByFilterCriteria", error); } }); }
this is my function for update detail... i also tried with save method but it create new row in the collection... so please tell me what should be done.. thnx
this is my Entity class...
import com.google.api.client.json.GenericJson; import com.google.api.client.util.Key; import com.kinvey.java.model.KinveyMetaData; public class LoginEntity extends GenericJson { @Key("_id") private String id; @Key("UserName") private String username; @Key("Password") private String password; @Key("FirstName") private String firstname; @Key("LastName") private String lastname; @Key("Email") private String email; @Key("Role") private String role; @Key("ProjectName") private String project; @Key("_kmd") private KinveyMetaData meta; // Kinvey metadata @Key("_acl") private KinveyMetaData.AccessControlList acl; // Kinvey Access Control public LoginEntity(){ } public String getActionId(){ return id; } public void setActionId(String id){ this.id=id; } public String getUsername(){ return username; } public void setUsername(String username){ this.username=username; } public String getPassword(){ return password; } public void setPassword(String pass){ this.password=pass; } public String getEmail(){ return email; } public void setEmail(String email){ this.email=email; } public String getFirstName(){ return firstname; } public void setFirstName(String fname){ this.firstname=fname; } public String getLastName(){ return lastname; } public void setLastName(String lname){ this.lastname=lname; } public String getRole(){ return role; } public void setRole(String role){ this.role=role; } public String getProjectName(){ return project; } public void setProjectName(String pname){ this.project=pname; } }
Sukhpal:
It appears as though you aren't calling save after you add the new fields to your object, We added a comment where your save should go, could you give this a shot?
private void updateUserDetail() { LoginEntity userEntity = new LoginEntity(); AsyncAppData<LoginEntity> myData = kinveyClient.appData("LoginMaster", LoginEntity.class); myData.getEntity(id, new KinveyClientCallback<LoginEntity>() { @Override public void onSuccess(LoginEntity user) { user.setFirstName(et_firstname.getText().toString()); user.setLastName(et_lastname.getText().toString()); user.setEmail(et_Email.getText().toString()); user.setUsername(et_Username.getText().toString()); user.setRole(spr_Role.getSelectedItem().toString()); user.setProjectName(spr_Projects.getSelectedItem().toString()); //save here! Log.v(TAG, "received "+ user.getEmail()); } @Override public void onFailure(Throwable error) { Log.e(TAG, "failed to fetchByFilterCriteria", error); } }); }
Thanks,
Sukhpal Singh
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..