0

The Parse android SDK does not allow updating of a column in the user table while I am using getCurrentUser() method to mark it as authenticated. When I call saveInBackground() on it I get the following error in the log file:

Uncaught internal server error. { [MongoError: exception: Mod on _id not allowed] name: 'MongoError'

Below is the code I am using for saving:

byte[] data = "Working at Parse is great!".getBytes();
        final ParseFile file = new ParseFile("abcdef.txt", data);



    ParseUser currentUser = ParseUser.getCurrentUser();
        if (currentUser != null) {
            // do stuff with the user
            currentUser.put("column_name", file);
            currentUser.saveInBackground(new SaveCallback() {
                @Override
                public void done(ParseException e) {
                    if (e == null) {
                        Log.i("KQ", "update successfully");
                    } else {
                        Log.i("KQ", "update error e = " + e);
                    }
                }
            });
        } else {
            // show the signup or login screen
            Log.i("KQ", "else");
        }
Tom Fox
  • 897
  • 3
  • 14
  • 34
Debugger
  • 491
  • 4
  • 21

2 Answers2

0

You have to save the ParseFile before attaching it to the User object. Your code should be like this

byte[] data = "Working at Parse is great!".getBytes();
    final ParseFile file = new ParseFile("abcdef.txt", data);
    file.saveInBackground(new SaveCallback() {
        @Override
        public void done(ParseException e) {
            if(e==null)
            {
                ParseUser currentUser = ParseUser.getCurrentUser();
                if (currentUser != null) {
                    // do stuff with the user
                    currentUser.put("column_name", file);
                    currentUser.saveInBackground(new SaveCallback() {
                        @Override
                        public void done(ParseException e) {
                            if (e == null) {
                                Log.i("KQ", "update successfully");
                            } else {
                                Log.i("KQ", "update error e = " + e);
                            }
                        }
                    });
                } else {
                    // show the signup or login screen
                    Log.i("KQ", "else");
                }
            }
        }
    });
James Falade
  • 189
  • 2
  • 5
  • problem is not with saving file problem is that while updating record in the table mongo does not allow to update _id which is primary key, any idea what to do with that or how we can remove the id parameter in the retrofit or android – Debugger Oct 02 '17 at 05:25
0

Till I get a good answer.I am currently using my cloud code beforeSave trigger in parse to remove the id field to get rid of the exception and unblock my work. any good answer will still be appreciated.

code I am using right now is as follows in the cloud code.

Parse.Cloud.beforeSave(Parse.User, function(request, response) {
    // For Android SDK remove id field while updating a user becasue it was creating MongoDB Exception in android.
    if (request.object.get("updatedFrom") == 'android') {
        request.object.unset("updatedFrom");
        request.object.unset("id");
    }
    response.success();
});

thanks.

Debugger
  • 491
  • 4
  • 21