Parse Android SDK is not allowing delete request and returns [MongoError: exception: Mod on _id not allowed] in the log

Parse Android SDK is not allowing delete request and returns [MongoError: exception: Mod on _id not allowed] in the log

Parse android SDK 不允许更新用户中的列 table 当我使用 getCurrentUser() 方法将其标记为已验证时。当我对其调用 saveInBackground() 时,我在日志文件中收到以下错误:

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

下面是我用来保存的代码:

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");
        }

您必须在将 ParseFile 附加到 User 对象之前保存它。 你的代码应该是这样的

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");
                }
            }
        }
    });

直到我得到一个好的 answer.I 我目前正在使用我的云代码 beforeSave 触发器在解析中删除 id 字段以消除异常并取消阻止我的工作。 任何好的答案仍然会受到赞赏。

我现在使用的代码在云端代码如下

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();
});

谢谢。