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!

ian
  • 1,002
  • 2
  • 12
  • 29

1 Answers1

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");
        }
    });
});
Dehli
  • 5,950
  • 5
  • 29
  • 44
  • 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] – ian Sep 14 '14 at 22:39
  • One step closer Dehli but it failed with error this time. – ian Sep 14 '14 at 23:15
  • Join me in [chat](http://chat.stackoverflow.com/rooms/61231/room-for-dehli-and-user2792129). – Dehli Sep 14 '14 at 23:16