0

Im having trouble with the my cloud code on parse.com. I have a class on parse.com in my data browser called "User". In this class I have seven users. each user has the keys "objectId" and "username". I want to import an array of the "objectId's" in the class "User", but I cannot retrieve them. It keeps saying "User" is not defined in my cloud code log. Here is my code:

Parse.Cloud.define("getUsers", function(request, response) {
  var query = new Parse.Query(User);
  var names = query.get("username");
  console.log("The users are" + names);

});

Im new to javascript so i would really appreciate some help. Thanks!

1 Answer 1

2

Your problem is because User is a Parse class. The code should be:

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

Additionally, most of your function needs rework.

Parse.Cloud.define("getUsers", function(request, response) {
    var query = new Parse.Query(Parse.User);
    query.find({
        success: function(results){
            var users = [];
            //extract out user names from results
            for(var i = 0; i < results.length; ++i){
                users.push(results[i].get("username"));
            }
            response.success(users);
        }, error: function(error){
            response.error("Error");
        }
    });
});
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for that but i changed it and now its logging this error: E2014-09-14T22:37:17.880Z] v10: Ran cloud function getUsers for user J7FKb38Iy1 with: Input: {} Failed with: success/error was not called I2014-09-14T22:37:18.076Z] The users are[object Object]
One step closer Dehli but it failed with error this time.
Join me in chat.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.