解析Cloudcode查询报错141

Parse Cloudcode query error 141

如果我 运行 在本地解析下面的 JavaScript 代码,查询工作正常。但是,当我将代码调整为 运行 作为 Parse cloudcode 时,不会执行相同的查询,并且当我测试查询内容时,我收到错误代码 141.

我已经在不同的点测试了这两个功能。参数comp_id和request.params.comp_id是一样的。

解析JavaScript查询(运行本地,工作正常)

function testOne(comp_id) {
Parse.initialize(*****,*****);
    var Competition = Parse.Object.extend("Competition");
    var query = new Parse.Query(Competition);
    console.log(query);                      // <~ gets a valid query
    query.get(comp_id, {
        success: function(competition) {
            console.log(competition.id);
        },
        error: function(competition, error) {console.log(error);}
    });
}

解析cloudcode查询(查询未执行,错误141)

Parse.Cloud.define("testOneCloud", function(request, response) {
    var comp_id = request.params.comp_id;

    var Competition = Parse.Object.extend("Competition");
    var query = new Parse.Query(Competition);
    msg = query;                               // <~ gets undefined error 141
    query.get(comp_id, {
        success: function(competition) {
            msg = competition.id;      // <~query success code does not get executed
        },
        error: function(competition, error) {console.log(error);}
    });

    response.success(msg);
});

知道为什么这两个看似相同的 Parse 程序中一个有效而另一个无效吗?

问题似乎是未声明的 msg 变量引起的。怎么样(消除额外的变量并使用承诺):

Parse.Cloud.define("testOneCloud", function(request, response) {
    var Competition = Parse.Object.extend("Competition");
    var query = new Parse.Query(Competition);
    query.get(request.params.comp_id).then(function(competition) {
        response.success(competition.id);
    }, function(error) {
        response.error(error);
    });
});