2

I'd like to check if a Cloud Code query response is null or empty. If the query find something, the code works. When there are no objects matching the query, I cannot handle it. What should I do?

Parse.Cloud.define("testing", function(request, response) {


var queryCheckRepeatedPost = new Parse.Query("Update");

queryCheckRepeatedPost.equalTo("updateValid", true); 
queryCheckRepeatedPost.first({
  useMasterKey: true,
    success: function(repeatedPost) {

    //Sometimes query return an object
    //Sometimes there are no objects to return

    },
    error: function() {
        response.error("Error 01");
    }
});

});

I tried:

Object.keys(repeatedPost).length === 0

var value = results[0].get("objectId");

 if (value == null){
 }

But none of them works.

2
  • if (repeteadPost) { // then is not null } ? Commented Sep 22, 2017 at 18:00
  • It does not work. Parse query returns success even if no object matches the query. I need to check if there is an object in this response. Commented Sep 22, 2017 at 18:18

1 Answer 1

2

I found the answer. When query returns an empty object it's undefined.

if (repeatedPost != undefined){

   //The object is not empty

}else{
  //the object is empty
}
Sign up to request clarification or add additional context in comments.

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.