1

I have defined a Parse core object of type X that has a pointer to another object of type Y as one of its attributes. There are about 1000 of type X objects defined and about 20 of type Y objects.

I need to create a JavaScript query that would start with object ID for a type Y object and get count of type X objects that contain pointer to a type Y object with this object ID.

This would be a very easy query against a traditional SQL-based back-end, but in Parse I can't find a solution.

1 Answer 1

1

You can easily do this using a relational query. Lets assume you have a local instance of an object of class Y, then the query would look like this

var ObjectX = Parse.Object.extend("X");
var query = new Parse.Query(ObjectX);
query.equalTo("objectYField", myObjectOfTypeY);
query.count({
  success: function(count) {
    // The count request succeeded. Show the count
  },
  error: function(error) {
    // The request failed
  }
});

One small caveat from the docs though

Count queries are rate limited to a maximum of 160 requests per minute. They can also return inaccurate results for classes with more than 1,000 objects. Thus, it is preferable to architect your application to avoid this sort of count operation (by using counters, for example.)

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

2 Comments

This query starts with the myObjectOfTypeY. In my case, I start with the objectId of myObjectOfTypeY, not the whole object.
If you just have the ID, you should be able to create an empty object of that type, set the ID and pass it in for objectYField (see parse.com/docs/js/api/symbols/…)

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.