Parse JavaScript Classes

Cloud Modules

Class Parse.Query

Parse.Query defines a query that is used to fetch Parse.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 Parse.Query(MyClass);
query.find({
  success: function(results) {
    // results is an array of Parse.Object.
  },

  error: function(error) {
    // error is an instance of Parse.Error.
  }
});

A Parse.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 Parse.Query(MyClass);
query.get(myId, {
  success: function(object) {
    // object is an instance of Parse.Object.
  },

  error: function(object, error) {
    // error is an instance of Parse.Error.
  }
});

A Parse.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 Parse.Query(MyClass);
query.count({
  success: function(number) {
    // There are number instances of MyClass.
  },

  error: function(error) {
    // error is an instance of Parse.Error.
  }
});

Class Summary
Constructor Attributes Constructor Name and Description
 
Parse.Query(objectClass)
Creates a new parse Parse.Query for the given Parse.Object subclass.
Method Summary
Method Attributes Method Name and Description
 
Sorts the results in ascending order by the given key, but can also add secondary sort descriptors without overwriting _order.
 
Sorts the results in descending order by the given key, but can also add secondary sort descriptors without overwriting _order.
 
ascending(key)
Sorts the results in ascending order by the given key.
 
collection(items, options)
Returns a new instance of Parse.Collection backed by this query.
 
containedIn(key, values)
Add a constraint to the query that requires a particular key's value to be contained in the provided list of values.
 
contains(key, substring)
Add a constraint for finding string values that contain a provided string.
 
containsAll(key, values)
Add a constraint to the query that requires a particular key's value to contain each one of the provided list of values.
 
count(options)
Counts the number of objects that match this query.
 
Sorts the results in descending order by the given key.
 
Add a constraint for finding objects that do not contain a given key.
 
doesNotMatchKeyInQuery(key, queryKey, query)
Add a constraint that requires that a key's value not match a value in an object returned by a different Parse.Query.
 
doesNotMatchQuery(key, query)
Add a constraint that requires that a key's value not matches a Parse.Query constraint.
 
each(callback, options)
Iterates over each result of a query, calling a callback for each one.
 
endsWith(key, suffix)
Add a constraint for finding string values that end with a provided string.
 
equalTo(key, value)
Add a constraint to the query that requires a particular key's value to be equal to the provided value.
 
exists(key)
Add a constraint for finding objects that contain the given key.
 
find(options)
Retrieves a list of ParseObjects that satisfy this query.
 
first(options)
Retrieves at most one Parse.Object that satisfies this query.
 
get(objectId, options)
Constructs a Parse.Object whose id is already known by fetching data from the server.
 
greaterThan(key, value)
Add a constraint to the query that requires a particular key's value to be greater than the provided value.
 
Add a constraint to the query that requires a particular key's value to be greater than or equal to the provided value.
 
include(key)
Include nested Parse.Objects for the provided key.
 
lessThan(key, value)
Add a constraint to the query that requires a particular key's value to be less than the provided value.
 
lessThanOrEqualTo(key, value)
Add a constraint to the query that requires a particular key's value to be less than or equal to the provided value.
 
limit(n)
Sets the limit of the number of results to return.
 
matches(key, regex, modifiers)
Add a regular expression constraint for finding string values that match the provided regular expression.
 
matchesKeyInQuery(key, queryKey, query)
Add a constraint that requires that a key's value matches a value in an object returned by a different Parse.Query.
 
matchesQuery(key, query)
Add a constraint that requires that a key's value matches a Parse.Query constraint.
 
near(key, point)
Add a proximity based constraint for finding objects with key point values near the point given.
 
notContainedIn(key, values)
Add a constraint to the query that requires a particular key's value to not be contained in the provided list of values.
 
notEqualTo(key, value)
Add a constraint to the query that requires a particular key's value to be not equal to the provided value.
<static>  
Parse.Query.or(var_args)
Constructs a Parse.Query that is the OR of the passed in queries.
 
select(keys)
Restrict the fields of the returned Parse.Objects to include only the provided keys.
 
skip(n)
Sets the number of results to skip before returning any results.
 
startsWith(key, prefix)
Add a constraint for finding string values that start with a provided string.
 
Returns a JSON representation of this query.
 
withinGeoBox(key, southwest, northeast)
Add a constraint to the query that requires a particular key's coordinates be contained within a given rectangular geographic bounding box.
 
withinKilometers(key, point, maxDistance)
Add a proximity based constraint for finding objects with key point values near the point given and within the maximum distance given.
 
withinMiles(key, point, maxDistance)
Add a proximity based constraint for finding objects with key point values near the point given and within the maximum distance given.
 
withinRadians(key, point, maxDistance)
Add a proximity based constraint for finding objects with key point values near the point given and within the maximum distance given.
Class Detail
Parse.Query(objectClass)
Creates a new parse Parse.Query for the given Parse.Object subclass.
Parameters:
objectClass
- An instance of a subclass of Parse.Object, or a Parse className string.
Method Detail
{Parse.Query} addAscending(key)
Sorts the results in ascending order by the given key, but can also add secondary sort descriptors without overwriting _order.
Parameters:
{(String|String[]|...String} key
The key to order by, which is a string of comma separated values, or an Array of keys, or multiple keys.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} addDescending(key)
Sorts the results in descending order by the given key, but can also add secondary sort descriptors without overwriting _order.
Parameters:
{(String|String[]|...String} key
The key to order by, which is a string of comma separated values, or an Array of keys, or multiple keys.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} ascending(key)
Sorts the results in ascending order by the given key.
Parameters:
{(String|String[]|...String} key
The key to order by, which is a string of comma separated values, or an Array of keys, or multiple keys.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Collection} collection(items, options)
Returns a new instance of Parse.Collection backed by this query.
Parameters:
{Array} items
An array of instances of Parse.Object with which to start this Collection.
{Object} options
An optional object with Backbone-style options. Valid options are:
  • model: The Parse.Object subclass that this collection contains.
  • query: An instance of Parse.Query to use when fetching items.
  • comparator: A string property name or function to sort by.
Returns:
{Parse.Collection}

{Parse.Query} containedIn(key, values)
Add a constraint to the query that requires a particular key's value to be contained in the provided list of values.
Parameters:
{String} key
The key to check.
{Array} values
The values that will match.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} contains(key, substring)
Add a constraint for finding string values that contain a provided string. This may be slow for large datasets.
Parameters:
{String} key
The key that the string to match is stored in.
{String} substring
The substring that the value must contain.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} containsAll(key, values)
Add a constraint to the query that requires a particular key's value to contain each one of the provided list of values.
Parameters:
{String} key
The key to check. This key's value must be an array.
{Array} values
The values that will match.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Promise} count(options)
Counts the number of objects that match this query. Either options.success or options.error is called when the count completes.
Parameters:
{Object} options
A Backbone-style options object. Valid options are:
  • success: Function to call when the count completes successfully.
  • error: Function to call when the find fails.
  • useMasterKey: In Cloud Code and Node only, causes the Master Key to be used for this request.
Returns:
{Parse.Promise} A promise that is resolved with the count when the query completes.

{Parse.Query} descending(key)
Sorts the results in descending order by the given key.
Parameters:
{(String|String[]|...String} key
The key to order by, which is a string of comma separated values, or an Array of keys, or multiple keys.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} doesNotExist(key)
Add a constraint for finding objects that do not contain a given key.
Parameters:
{String} key
The key that should not exist
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} doesNotMatchKeyInQuery(key, queryKey, query)
Add a constraint that requires that a key's value not match a value in an object returned by a different Parse.Query.
Parameters:
{String} key
The key that contains the value that is being excluded.
{String} queryKey
The key in the objects returned by the query to match against.
{Parse.Query} query
The query to run.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} doesNotMatchQuery(key, query)
Add a constraint that requires that a key's value not matches a Parse.Query constraint.
Parameters:
{String} key
The key that the contains the object to match the query.
{Parse.Query} query
The query that should not match.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Promise} each(callback, options)
Iterates over each result of a query, calling a callback for each one. If the callback returns a promise, the iteration will not continue until that promise has been fulfilled. If the callback returns a rejected promise, then iteration will stop with that error. The items are processed in an unspecified order. The query may not have any sort order, and may not use limit or skip.
Parameters:
{Function} callback
Callback that will be called with each result of the query.
{Object} options
An optional Backbone-like options object with success and error callbacks that will be invoked once the iteration has finished.
Returns:
{Parse.Promise} A promise that will be fulfilled once the iteration has completed.

{Parse.Query} endsWith(key, suffix)
Add a constraint for finding string values that end with a provided string. This will be slow for large datasets.
Parameters:
{String} key
The key that the string to match is stored in.
{String} suffix
The substring that the value must end with.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} equalTo(key, value)
Add a constraint to the query that requires a particular key's value to be equal to the provided value.
Parameters:
{String} key
The key to check.
value
The value that the Parse.Object must contain.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} exists(key)
Add a constraint for finding objects that contain the given key.
Parameters:
{String} key
The key that should exist.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Promise} find(options)
Retrieves a list of ParseObjects that satisfy this query. Either options.success or options.error is called when the find completes.
Parameters:
{Object} options
A Backbone-style options object. Valid options are:
  • success: Function to call when the find completes successfully.
  • error: Function to call when the find fails.
  • useMasterKey: In Cloud Code and Node only, causes the Master Key to be used for this request.
Returns:
{Parse.Promise} A promise that is resolved with the results when the query completes.

{Parse.Promise} first(options)
Retrieves at most one Parse.Object that satisfies this query. Either options.success or options.error is called when it completes. success is passed the object if there is one. otherwise, undefined.
Parameters:
{Object} options
A Backbone-style options object. Valid options are:
  • success: Function to call when the find completes successfully.
  • error: Function to call when the find fails.
  • useMasterKey: In Cloud Code and Node only, causes the Master Key to be used for this request.
Returns:
{Parse.Promise} A promise that is resolved with the object when the query completes.

get(objectId, options)
Constructs a Parse.Object whose id is already known by fetching data from the server. Either options.success or options.error is called when the find completes.
Parameters:
{String} objectId
The id of the object to be fetched.
{Object} options
A Backbone-style options object. Valid options are:
  • success: A Backbone-style success callback
  • error: An Backbone-style error callback.
  • useMasterKey: In Cloud Code and Node only, causes the Master Key to be used for this request.

{Parse.Query} greaterThan(key, value)
Add a constraint to the query that requires a particular key's value to be greater than the provided value.
Parameters:
{String} key
The key to check.
value
The value that provides an lower bound.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} greaterThanOrEqualTo(key, value)
Add a constraint to the query that requires a particular key's value to be greater than or equal to the provided value.
Parameters:
{String} key
The key to check.
value
The value that provides an lower bound.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} include(key)
Include nested Parse.Objects for the provided key. You can use dot notation to specify which fields in the included object are also fetch.
Parameters:
{String} key
The name of the key to include.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} lessThan(key, value)
Add a constraint to the query that requires a particular key's value to be less than the provided value.
Parameters:
{String} key
The key to check.
value
The value that provides an upper bound.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} lessThanOrEqualTo(key, value)
Add a constraint to the query that requires a particular key's value to be less than or equal to the provided value.
Parameters:
{String} key
The key to check.
value
The value that provides an upper bound.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} limit(n)
Sets the limit of the number of results to return. The default limit is 100, with a maximum of 1000 results being returned at a time.
Parameters:
{Number} n
the number of results to limit to.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} matches(key, regex, modifiers)
Add a regular expression constraint for finding string values that match the provided regular expression. This may be slow for large datasets.
Parameters:
{String} key
The key that the string to match is stored in.
{RegExp} regex
The regular expression pattern to match.
modifiers
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} matchesKeyInQuery(key, queryKey, query)
Add a constraint that requires that a key's value matches a value in an object returned by a different Parse.Query.
Parameters:
{String} key
The key that contains the value that is being matched.
{String} queryKey
The key in the objects returned by the query to match against.
{Parse.Query} query
The query to run.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} matchesQuery(key, query)
Add a constraint that requires that a key's value matches a Parse.Query constraint.
Parameters:
{String} key
The key that the contains the object to match the query.
{Parse.Query} query
The query that should match.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} near(key, point)
Add a proximity based constraint for finding objects with key point values near the point given.
Parameters:
{String} key
The key that the Parse.GeoPoint is stored in.
{Parse.GeoPoint} point
The reference Parse.GeoPoint that is used.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} notContainedIn(key, values)
Add a constraint to the query that requires a particular key's value to not be contained in the provided list of values.
Parameters:
{String} key
The key to check.
{Array} values
The values that will not match.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} notEqualTo(key, value)
Add a constraint to the query that requires a particular key's value to be not equal to the provided value.
Parameters:
{String} key
The key to check.
value
The value that must not be equalled.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

<static> {Parse.Query} Parse.Query.or(var_args)
Constructs a Parse.Query that is the OR of the passed in queries. For example:
var compoundQuery = Parse.Query.or(query1, query2, query3);
will create a compoundQuery that is an or of the query1, query2, and query3.
Parameters:
{...Parse.Query} var_args
The list of queries to OR.
Returns:
{Parse.Query} The query that is the OR of the passed in queries.

{Parse.Query} select(keys)
Restrict the fields of the returned Parse.Objects to include only the provided keys. If this is called multiple times, then all of the keys specified in each of the calls will be included.
Parameters:
{Array} keys
The names of the keys to include.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} skip(n)
Sets the number of results to skip before returning any results. This is useful for pagination. Default is to skip zero results.
Parameters:
{Number} n
the number of results to skip.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} startsWith(key, prefix)
Add a constraint for finding string values that start with a provided string. This query will use the backend index, so it will be fast even for large datasets.
Parameters:
{String} key
The key that the string to match is stored in.
{String} prefix
The substring that the value must start with.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Object} toJSON()
Returns a JSON representation of this query.
Returns:
{Object} The JSON representation of the query.

{Parse.Query} withinGeoBox(key, southwest, northeast)
Add a constraint to the query that requires a particular key's coordinates be contained within a given rectangular geographic bounding box.
Parameters:
{String} key
The key to be constrained.
{Parse.GeoPoint} southwest
The lower-left inclusive corner of the box.
{Parse.GeoPoint} northeast
The upper-right inclusive corner of the box.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} withinKilometers(key, point, maxDistance)
Add a proximity based constraint for finding objects with key point values near the point given and within the maximum distance given. Radius of earth used is 6371.0 kilometers.
Parameters:
{String} key
The key that the Parse.GeoPoint is stored in.
{Parse.GeoPoint} point
The reference Parse.GeoPoint that is used.
{Number} maxDistance
Maximum distance (in kilometers) of results to return.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} withinMiles(key, point, maxDistance)
Add a proximity based constraint for finding objects with key point values near the point given and within the maximum distance given. Radius of earth used is 3958.8 miles.
Parameters:
{String} key
The key that the Parse.GeoPoint is stored in.
{Parse.GeoPoint} point
The reference Parse.GeoPoint that is used.
{Number} maxDistance
Maximum distance (in miles) of results to return.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

{Parse.Query} withinRadians(key, point, maxDistance)
Add a proximity based constraint for finding objects with key point values near the point given and within the maximum distance given.
Parameters:
{String} key
The key that the Parse.GeoPoint is stored in.
{Parse.GeoPoint} point
The reference Parse.GeoPoint that is used.
{Number} maxDistance
Maximum distance (in radians) of results to return.
Returns:
{Parse.Query} Returns the query, so you can chain this call.

Documentation generated by JsDoc Toolkit.