Home Reference Source
import {Query} from './core/query.js'
public class | source

Query

The Query class is used to query for a subset of entities using the Kinvey API.

Example:

var query = new Kinvey.Query();
query.equalTo('name', 'Kinvey');

Constructor Summary

Public Constructor
public

constructor(options: Object): Query

Create an instance of the Query class.

Member Summary

Public Members
public get
public set
public get
public set
public get
public set
public get
public set
public get
public set

Method Summary

Public Methods
public

addFilter(field: string, condition: string, values: *): Query

Adds a filter to the query.

public

and(args: ...Query | ...Object): Query

Performs a logical AND operation on the query and the provided queries.

public

Adds an ascending sort modifier to the query.

public

contains(field: string, values: array): Query

Adds a contains filter to the query.

public

containsAll(field: string, values: Array): Query

Adds a contains all filter to the query.

public

Adds an descending sort modifier to the query.

public

equalTo(field: string, value: *): Query

Adds an equal to filter to the query.

public

exists(field: string, flag: boolean): Query

Adds an exists filter to the query.

public

greaterThan(field: string, value: number | string): Query

Adds a greater than filter to the query.

public

Adds a greater than or equal to filter to the query.

public

Returns true or false depending on if the query is able to be processed offline.

public

lessThan(field: string, value: number | string): Query

Adds a less than filter to the query.

public

Adds a less than or equal to filter to the query.

public

matches(field: string, regExp: RegExp | string, options: Object): Query

Adds a match filter to the query.

public

mod(field: string, divisor: number, remainder: number): Query

Adds a modulus filter to the query.

public

near(field: string, coord: Array<number, number>, maxDistance: number): Query

Adds a near filter to the query.

public

nor(args: ...Query | ...Object): Query

Performs a logical NOR operation on the query and the provided queries.

public

notContainedIn(field: string, values: Array): Query

Adds a not contained in filter to the query.

public

notEqualTo(field: string, value: *): Query

Adds a not equal to filter to the query.

public

or(args: ...Query | ...Object): Query

Performs a logical OR operation on the query and the provided queries.

public

size(field: string, size: number): Query

Adds a size filter to the query.

public

Returns Object representation of the query.

public

Returns query string representation of the query.

public

Returns query string representation of the query.

public

withinBox(field: string, bottomLeftCoord: Array<number, number>, upperRightCoord: Array<number, number>): Query

Adds a within box filter to the query.

public

Adds a within polygon filter to the query.

Public Constructors

public constructor(options: Object): Query source

Create an instance of the Query class.

Params:

NameTypeAttributeDescription
options Object

Options

options.fields string[]
  • optional
  • default: []

Fields to select.

options.filter Object
  • optional
  • default: {}

MongoDB query.

options.sort Object
  • optional
  • default: {}

The sorting order.

options.limit number
  • optional
  • default: null
  • nullable: true

Number of entities to select.

options.skip number
  • optional
  • default: 0

Number of entities to skip from the start.

Return:

Query

The query.

Public Members

public get fields: string[] source

public set fields: string[] source

public get filter: Object source

public set filter: Object source

public get limit: number source

public set limit: number source

public get skip: number source

public set skip: number source

public get sort: Object source

public set sort: Object source

Public Methods

public addFilter(field: string, condition: string, values: *): Query source

Adds a filter to the query.

Params:

NameTypeAttributeDescription
field string

Field

condition string

Condition

values *

Values

Return:

Query

The query.

public and(args: ...Query | ...Object): Query source

Performs a logical AND operation on the query and the provided queries.

Params:

NameTypeAttributeDescription
args ...Query | ...Object

Queries

Return:

Query

The query.

Throw:

QueryError

query must be of type Array<Query> or Array<Object>.

See:

public ascending(field: string): Query source

Adds an ascending sort modifier to the query. Sorts by field, ascending.

Params:

NameTypeAttributeDescription
field string

Field

Return:

Query

The query.

public contains(field: string, values: array): Query source

Adds a contains filter to the query. Requires field to contain at least one of the members of list.

Params:

NameTypeAttributeDescription
field string

Field

values array

List of values.

Return:

Query

The query.

Throw:

QueryError

values must be of type Array.

See:

public containsAll(field: string, values: Array): Query source

Adds a contains all filter to the query. Requires field to contain all members of list.

Params:

NameTypeAttributeDescription
field string

Field

values Array

List of values.

Return:

Query

The query.

Throw:

QueryError

values must be of type Array.

See:

public descending(field: string): Query source

Adds an descending sort modifier to the query. Sorts by field, descending.

Params:

NameTypeAttributeDescription
field string

Field

Return:

Query

The query.

public equalTo(field: string, value: *): Query source

Adds an equal to filter to the query. Requires field to equal value. Any existing filters on field will be discarded.

Params:

NameTypeAttributeDescription
field string

Field

value *

Value

Return:

Query

The query.

See:

public exists(field: string, flag: boolean): Query source

Adds an exists filter to the query. Requires field to exist if flag is true, or not to exist if flag is false.

Params:

NameTypeAttributeDescription
field string

Field

flag boolean
  • optional
  • default: true

The exists flag.

Return:

Query

The query.

See:

public greaterThan(field: string, value: number | string): Query source

Adds a greater than filter to the query. Requires field to be greater than value.

Params:

NameTypeAttributeDescription
field string

Field

value number | string

Value

Return:

Query

The query.

Throw:

QueryError

value must be of type number or string.

See:

public greaterThanOrEqualTo(field: string, value: number | string): Query source

Adds a greater than or equal to filter to the query. Requires field to be greater than or equal to value.

Params:

NameTypeAttributeDescription
field string

Field.

value number | string

Value.

Return:

Query

The query.

Throw:

QueryError

value must be of type number or string.

See:

public isSupportedOffline(): boolean source

Returns true or false depending on if the query is able to be processed offline.

Return:

boolean

True if the query is supported offline otherwise false.

public lessThan(field: string, value: number | string): Query source

Adds a less than filter to the query. Requires field to be less than value.

Params:

NameTypeAttributeDescription
field string

Field

value number | string

Value

Return:

Query

The query.

Throw:

QueryError

value must be of type number or string.

See:

public lessThanOrEqualTo(field: string, value: number | string): Query source

Adds a less than or equal to filter to the query. Requires field to be less than or equal to value.

Params:

NameTypeAttributeDescription
field string

Field

value number | string

Value

Return:

Query

The query.

Throw:

QueryError

value must be of type number or string.

See:

public matches(field: string, regExp: RegExp | string, options: Object): Query source

Adds a match filter to the query. Requires field to match regExp.

Params:

NameTypeAttributeDescription
field string

Field

regExp RegExp | string

Regular expression.

options Object
  • optional

Options

options.ignoreCase boolean
  • optional
  • default: inherit

Toggles case-insensitivity.

options.multiline boolean
  • optional
  • default: inherit

Toggles multiline matching.

options.extended boolean
  • optional
  • default: false

Toggles extended capability.

options.dotMatchesAll boolean
  • optional
  • default: false

Toggles dot matches all.

Return:

Query

The query.

See:

public mod(field: string, divisor: number, remainder: number): Query source

Adds a modulus filter to the query. Requires field modulo divisor to have remainder remainder.

Params:

NameTypeAttributeDescription
field string

Field

divisor number

Divisor

remainder number
  • optional
  • default: 0

Remainder

Return:

Query

The query.

Throw:

QueryError

divisor must be of type: number.

QueryError

remainder must be of type: number.

See:

public near(field: string, coord: Array<number, number>, maxDistance: number): Query source

Adds a near filter to the query. Requires field to be a coordinate within maxDistance of coord. Sorts documents from nearest to farthest.

Params:

NameTypeAttributeDescription
field string

The field.

coord Array<number, number>

The coordinate (longitude, latitude).

maxDistance number
  • optional

The maximum distance (miles).

Return:

Query

The query.

Throw:

QueryError

coord must be of type Array<number, number>.

See:

public nor(args: ...Query | ...Object): Query source

Performs a logical NOR operation on the query and the provided queries.

Params:

NameTypeAttributeDescription
args ...Query | ...Object

Queries

Return:

Query

The query.

Throw:

QueryError

query must be of type Array<Query> or Array<Object>.

See:

public notContainedIn(field: string, values: Array): Query source

Adds a not contained in filter to the query. Requires field not to contain any of the members of list.

Params:

NameTypeAttributeDescription
field string

Field

values Array

List of values.

Return:

Query

The query.

Throw:

QueryError

values must be of type Array.

See:

public notEqualTo(field: string, value: *): Query source

Adds a not equal to filter to the query. Requires field not to equal value.

Params:

NameTypeAttributeDescription
field string

Field

value *

Value

Return:

Query

The query.

See:

public or(args: ...Query | ...Object): Query source

Performs a logical OR operation on the query and the provided queries.

Params:

NameTypeAttributeDescription
args ...Query | ...Object

Queries.

Return:

Query

The query.

Throw:

QueryError

query must be of type Array<Query> or Array<Object>.

See:

public size(field: string, size: number): Query source

Adds a size filter to the query. Requires field to be an Array with exactly size members.

Params:

NameTypeAttributeDescription
field string

Field

size number

Size

Return:

Query

The query.

Throw:

QueryError

size must be of type: number.

See:

public toPlainObject(): Object source

Returns Object representation of the query.

Return:

Object

Object

public toQueryString(): Object source

Returns query string representation of the query.

Return:

Object

Query string object.

public toString(): string source

Returns query string representation of the query.

Return:

string

Query string string.

public withinBox(field: string, bottomLeftCoord: Array<number, number>, upperRightCoord: Array<number, number>): Query source

Adds a within box filter to the query. Requires field to be a coordinate within the bounds of the rectangle defined by bottomLeftCoord, bottomRightCoord.

Params:

NameTypeAttributeDescription
field string

The field.

bottomLeftCoord Array<number, number>

The bottom left coordinate (longitude, latitude).

upperRightCoord Array<number, number>

The bottom right coordinate (longitude, latitude).

Return:

Query

The query.

Throw:

QueryError

bottomLeftCoord must be of type Array<number, number>.

QueryError

bottomRightCoord must be of type Array<number, number>.

See:

public withinPolygon(field: string, coords: Array<Array<number, number>>): Query source

Adds a within polygon filter to the query. Requires field to be a coordinate within the bounds of the polygon defined by coords.

Params:

NameTypeAttributeDescription
field string

The field.

coords Array<Array<number, number>>

List of coordinates.

Return:

Query

The query.

Throw:

QueryError

coords must be of type Array<Array<number, number>>.

See: