2

I'm a new user and novice coder trying to learn the basics of Cloud Code (please bear with me). I've been following online tutorials and I'm trying to replicate basic functionality to increment my knowledge and understanding.

I created a very simple class ("Students") with 2 objects: Screenshot

I just want to be able to run simple queries on the data to understand how queries work. However, using almost exactly the same code found in several online tutorials, I can't seem to get any results. I don't get errors, but I'm not able to get results when I create simple matches like query on "Name", "Alex":

Parse.Cloud.define("test", function(request, response) {
  var Student = Parse.Object.extend("Student");
  var query = new Parse.Query(Student);
  query.equalTo("Grade",95);
  query.find({
    success: function(results){
     console.log("received " + results.length + " result(s)");
    },
    error: function(error) {
     //error
     console.log("error: " + error);
    }
  });
  response.success("done");
});

After running this code, the only thing I see in my cloud log after the usual deploy and run text is this:

 Input: {}
 Result: done

This should be easy for most of you to troubleshoot. Just trying to learn this the hard way. Thanks!

1 Answer 1

4

Put your "response.success("done");" in the "success: function(results)" that should fix it.

Sign up to request clarification or add additional context in comments.

2 Comments

just curious, why does it need to be in that specific area?
Basically if you call response.success or response.error it stops the execution of the code, so you want to move that to your inner most nested statement, so that it will execute everything, things don't execute in a linear way on parse, in your code response.success was being executed before query.find completed, when you moved response.success into query.find, that completed before response.success was called.

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.