解析云代码-在“”中查询用户问题;正常的“;作用

Parse cloud code - query user issue in "normal" function

本文关键字:用户 问题 作用 查询 代码      更新时间:2023-10-04

当使用"标准"函数时,我无法获得云代码来查询用户。。。

如果我定义函数(如下所示),它可以正常工作。。。

Parse.Cloud.define("findUser1", function(request, response){
   Parse.Cloud.useMasterKey();
   var query = new Parse.Query(Parse.User);
   query.equalTo("objectId", "2FSYI1hoJ8"); // "2FSYI1hoJ8" is the objectId of the User I am looking for
   query.first({
       success: function(user){
       response.success(user);
   },
   error: function(error) {
       console.error(error);
       response.error("An error occured while lookup the users objectid");
   }
   });
 });

在这个版本中,函数会被调用,但里面的查询不会。。。

function findThisUser(theObject){
    console.log("findThisUser has fired... " + theObject); //confirms "theObject" has been passed in
    Parse.Cloud.useMasterKey();
    var query = new Parse.Query(Parse.User);
    query.equalTo("objectId", "2FSYI1hoJ8"); // "2FSYI1hoJ8" is the value of "theObject", just hard coded for testing
   query.first({
       success: function(users){
       console.log("the user is... " + users);
       // do needed functionality here
   },
       error: function(error) {
       console.error(error);
   }
   });
};

云代码不允许全局变量,我也不知道如何将一个变量传递给另一个"定义"的函数。这一点至关重要,因为必须调用外部函数才能在返回的用户上运行所需的任务。(这种情况在其他地方发生,必须在其他一切发生之后发生。这是确认,应该也被其他函数使用)迄今为止发现的所有潜在信息都没有帮助,我在服务器端javascript方面的唯一经验是我从其他云代码中拼凑出来的。。。

你知道我缺少什么吗?

这个链接可能会有所帮助,我昨天也遇到了类似的问题,在稍微移动了代码之后,得到了response.success(user);在我的职责范围内,一切都很好。

解析云代码检索具有objectId 的用户

不是你的确切问题,但这可能会有所帮助。

这是我现在使用的代码:

Parse.Cloud.define("getUserById", function (request, response) {
//Example where an objectId is passed to a cloud function.
var id = request.params.objectId;
Parse.Cloud.useMasterKey();
var query = new Parse.Query(Parse.User);
query.equalTo("ObjectId", id);
query.first(
{
    success: function(res) {
        response.success(res);
    },
    error: function(err) {
        response.error(err);
    }
});

});