1

In Parse's javascript API, does the count method not do anything if no objects are returned? I'm trying to query for a new table I just added, and I can't seem to get a query to return results.

var contactObj = Parse.Object.extend("Contact");
var contactQuery = new Parse.Query(contactObj);
contactQuery.equalTo("phone", req.body.From);

    contactQuery.count({
      success: function(number) {
        // There are number instances of MyClass.
        console.log("something");
      },
      error: function(error) {
    // error is an instance of Parse.Error.
            console.log("error");
    }
});

In this code, when run, no console.logs are received, but the enclosing method that I call does print that it has been run. Does count not get to success OR failure if the count is 0?

2 Answers 2

1

Your are missing the response.success and response.error calls, but console logs are still writing. See below

Your exact piece of code is returning in your workstation console "success/error was not called" when running. But still in parse portal console you see "something" output...

Output parse console in your local machine:

{"code":141,"error":"success/error was not called"}

Output parse portal in Logs

Failed with: success/error was not called
I2015-01-14T09:28:26.174Z] something

I'd added below two lines:

response.success("something success");
response.error("something error");

so actual code will be like the one below:

Parse.Cloud.define("StackOverflowTesting", function(request, response) {
   var contactObj = Parse.Object.extend("Contact");
   var contactQuery = new Parse.Query(contactObj);
   contactQuery.equalTo("phone", req.body.From);
   contactQuery.count({
         success: function(number) {
           // There are number instances of MyClass.
           console.log("something success console");
           response.success("something success");
         },
         error: function(error) {
         // error is an instance of Parse.Error.
             console.log("something error console");
             response.error("something error");
     }
   });

});

outputs workstation console:

{"result":"something success"}

Parse portal Log:

Result: something success 
I2015-01-14T09:29:54.355Z] something success console
Sign up to request clarification or add additional context in comments.

3 Comments

Sorry this wasn't clear, but there are below this query more queries and a push, which at the lowest level will call response.success/response.error. I thought that if I did those too early then the execution would terminate before reaching my further code.
Nothing in the OP suggests this code was running in the cloud, sounds more like it was being run client-side and having issues when the table is empty.
@BHendricks you can pass your callback (or response) function(s) down the chain, e.g. function (req, callbacks) { var query = new Parse.Query(Parse.User); query.containedIn('phoneNumber', request.body.phoneNumbers); query.find(callbacks); };
0

I had a similar issue where console.logs were not called from success and error blocks. This was caused due to an infinite while loop after the query. Something of this kind -

    var c = 0;
    var query = new Parse.Query("XXXXX");
    query.equalTo("YYYY","abc");
    query.count({
                success: function(count) {
                         c += 1;
                         console.log("success");
                },
                error: function(error) {
                       c += 1;
                       console.log("failure");
                }
                });
   while (c < 1){
   }
   ..........

Node.js is asynchronous but it's also single-threaded. Make sure you do not have any such code blocks which are holding up the execution.

Also, query.count gets to success even if the no. of results is 0.

Comments

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.