解析云代码查询错误141

时间:2015-01-13 21:23:15

标签: javascript parse-platform cloud-code

如果我在本地运行Parse JavaScript代码,查询工作正常。但是,当我调整代码以运行Parse云代码时,不执行相同的查询,当我测试查询内容时,我得到代码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);}
    });
}

解析云代码查询(查询未执行,错误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程序中的一个有效,而另一个没有?

1 个答案:

答案 0 :(得分:1)

似乎未声明的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);
    });
});