阅读背景:

Parse.com CloudCode使用username参数查找Parse.User objectId

来源:互联网 

I have created a CloudCode function that looks up the users ObjectId based off of their Username.

我创建了一个CloudCode函数,它根据用户名查找用户ObjectId。

the result I receive are

我得到的结果是

Ran cloud function findUserByEmail with: Input: {"email":"[email protected]"} Result: undefined

Ran cloud函数findUserByEmail with:输入:{“email”:“[email protected]”}结果:undefined

this is my JavaScript for the CloudCode

这是我的CloudCode的JavaScript

------------------------------------SOLUTION-----------------------------------------

- - - - - - - - - - - - - - - - - - 解 - - - - - - - ----------------------------

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

   if(!email) {
   response.error("Missing parameter: email");
   return ;
   }

   Parse.Cloud.useMasterKey();

   var query = new Parse.Query(Parse.User);

   query.equalTo("username", email);
   query.**first**({
   success: function(user){
       var objectId = user.id;

   response.success(objectId);
   },

   error: function(error) {
       console.error(error);
       response.error("An error occured while lookup the users objectid");
   }

   });

 });

Not sure why my Results "Undefined"

不确定为什么我的结果“未定义”

1 个解决方案

#1


4  

query.find() returns an array of results, so user.id would definitely be undefined.

query.find()返回一个结果数组,因此user.id肯定是未定义的。

I'd prefer query.first() which returns just one.

我更喜欢query.first(),它只返回一个。

This should work if you just change find to first.

如果你只是将find改为first,这应该可行。


分享到: