Usage and Methods Overview

The Backend Services JavaScript SDK provides a set of methods that allow you to perform projection, sorting, filtering, paging, and so on when making data queries. For aggregation and grouping, see Data Aggregation and Grouping.

In this article:

Usage

The Backend Services JavaScript SDK utilizes Query objects to perform queries. A Query object is created by calling its constructor:

var query = new Everlive.Query();

The methods of the Query objects are fluent. In other words, you can chain them like in the following example, where where(), select(), order(), take(), and skip() are all Query methods. Everything between where() and done() are WhereQuery specifications.

query.where().gt('age', 5).lt('age', 15).done().
    select('title', 'summary').order('age').take(10).skip(10);

List of Methods

The Query class comes with a number of member functions that cover a wide range of operations that you might want to perform on your data. These are listed below as well as in the Backend Services JavaScript SDK API Reference.

Filtering

Filtering is implemented through the WhereQuery class. The full list of WhereQuery methods is shown below. These methods are only applicable to read, update, and delete requests. Details as well as examples can be found in Filtering. Methods specific to geographical location are described in Geolocation.

  • eq(field, value), equal(field, value)—Searches for data items where the specified field has the specified value.
  • ne(field, value), notEqual(field, value)—Searches for data items where the specified field is not equal to the specified value.
  • gt(field, value), greaterThan(field, value)—Searches for data items where the value of the specified field is greater than the specified value.
  • gte(field, value), greaterThanEqual(field, value)—Searches for data items where the value of the specified field is greater than or equal to the specified value.
  • lt(field, value), lessThan(field, value)—Searches for data items where the value of the specified field is less than the specified value.
  • lte(field, value), lessThanEqual(field, value)—Searches for data items where the value of the specified field is less than or equal to the specified value.
  • isin(field, [value1, value2, ...])—Searches for data items where the value of the specified field equals any of the values inside the specified array.
  • notin(field, [value1, value2, ...])—Searches for data items where the value of the specified field is not equal to any of the values inside the specified array or data items that do not include the field.
  • all(arrayField, [value1, value2, ...])—Searches for data items where the specified arrayField contains all the values specified as the seconds argument.
  • size(arrayField, number)—Searches for data items where the specified arrayField contains exactly the specified number of values.
  • regex(field, expression), regex(field, string, flags)—Specifies a regular expression to be used as a filtering criterion.
  • startsWith(stringField, string, options)—Searches for data items where the specified stringField starts with the specified string. The options argument specifies regex-like flags that control things like case sensitivity.
  • endsWith(stringField, string, options)—Searches for data items where the specified stringField ends with the specified string. The options argument specifies regex-like flags that control things like case sensitivity.
  • not()—Negates the condition that follows.
  • and()—Creates a complex condition where the following conditions are operands of logical conjunction. This is also the default logical operator that is applied implicitly when no logical operator is specified.
  • or()—Creates a complex condition where the following conditions are operands of logical disjunction.
  • withinCenterSphere(field, center, radius, [metric])—Searches for GeoPoints within a specified radius from a specified point.
  • nearSphere(field, center, distance, [metric])—Same as withinCenterSphere() but returns the results sorted from nearest to farthest and limits the count to 100.
  • withinBox(field, pointBottomLeft, pointUpperRight)—Searches for GeoPoints within the confines of a rectangle specified using a pair of GeoPoints.
  • withinPolygon(field, points)—Searches for GeoPoints within the confines of a polygon specified using an array of points.
  • nearSphere(field, point, distance, [metric])—Searches for GeoPoints within a specified radius from a specified GeoPoint.

Paging

The following couple of methods can be combined to read results in pages. They are only applicable to read and delete requests. Details as well as examples can be found in Paging.

  • take(number)—Specifies the number of items to be retrieved in a single page. Combine with skip() for paging.
  • skip(number)—Specifies how many items to omit when returning a result. Combine with take() for paging.

Sorting

The full list of sorting methods includes the following. They are only applicable to read and delete requests. Details as well as examples can be found in Sorting.

  • order(field)—Sorts the result items in ascending order.
  • orderDesc(field)—Sorts the result items in descending order.

Projection

The full list of projection methods includes the following. They are only applicable to read requests. Details as well as examples can be found in Getting a Subset of Fields.

  • select(field1, field2, ...)—Specifies what fields to be retrieved.

See Also

Start a free trial Request a demo
Contact us: +1-888-365-2779
sales@telerik.com
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All rights reserved.