Query

Query

AV.Query defines a query that is used to fetch AV.Objects. The most common use case is finding all objects that match a query through the find method. For example, this sample code fetches all objects of class MyClass. It calls a different function depending on whether the fetch succeeded or not.

var query = new AV.Query(MyClass);
query.find().then(function(results) {
  // results is an array of AV.Object.
}, function(error) {
  // error is an instance of AVError.
});

An AV.Query can also be used to retrieve a single object whose id is known, through the get method. For example, this sample code fetches an object of class MyClass and id myId. It calls a different function depending on whether the fetch succeeded or not.

var query = new AV.Query(MyClass);
query.get(myId).then(function(object) {
  // object is an instance of AV.Object.
}, function(error) {
  // error is an instance of AVError.
});

An AV.Query can also be used to count the number of objects that match the query without retrieving all of those objects. For example, this sample code counts the number of objects of the class MyClass

var query = new AV.Query(MyClass);
query.count().then(function(number) {
  // There are number instances of MyClass.
}, function(error) {
  // error is an instance of AVError.
});

Constructor

new Query(objectClass)

Source:
Creates a new AV.Query for the given AV.Object subclass.
Parameters:
Name Type Description
objectClass Class | String An instance of a subclass of AV.Object, or a AV className string.