Query

Query

Creates an instance of the query

Members

lessThan

Source:
This method provides only the entries with values less than the specified value for a field.
Example
extension.stack.ContentType('blog').lessThan('created_at','2015-06-22')

lessThanOrEqualTo

Source:
This method provides only the entries with values less than or equal to the specified value for a field.
Example
extension.stack.ContentType('blog').lessThanOrEqualTo('created_at','2015-03-12')

Methods

addParam(key, value) → {Query}

Source:
This method includes a query parameter in your query.
Example
extension.stack.ContentType('content_type_uid').Entry.Query().addParam('key', 'value').find().then().catch();
       
Parameters:
Name Type Description
key string Key of the parammeter
value string Value of the parammeter
Returns:
Type
Query

addQuery(key, value) → {Query}

Source:
This method includes a query parameter in your query.
Example
extension.stack.ContentType('content_type_uid').Entry.Query().addQuery('key', 'value').find().then().catch();
       
Parameters:
Name Type Description
key string Key of the parammeter
value string Value of the parammeter
Returns:
Type
Query

and(Array) → {Query}

Source:
This method performs the AND operation on the specified query objects and provides only the matching entries.
Examples

AND with raw queries

let Query1 = extension.stack.ContentType('blog').Entry.Query().where('title', 'Demo');
let Query2 = extension.stack.ContentType('blog').Entry.Query().lessThan('comments', 10);
let blogQuery = extension.stack.ContentType('blog').and(Query1, Query2)

.and with raw queries

let Query1 = extension.stack.ContentType('blog').Entry.Query().where('title', 'Demo').getQuery();
let Query2 = extension.stack.ContentType('blog').Entry.Query().lessThan('comments', 10).getQuery();
let blogQuery = extension.stack.ContentType('blog').and(Query1, Query2)
Parameters:
Name Type Description
Array object of query objects/raw queries to be taken into consideration
Returns:
Type
Query

ascending(key) → {Query}

Source:
This parameter sorts the entries in ascending order on the basis of the value of the specified field.
Example
extension.stack.ContentType('blog').ascending('created_at')
Parameters:
Name Type Description
key String Field UID to be used for sorting.
Returns:
Type
Query

containedIn(key, value) → {Query}

Source:
This method provides only the entries with values matching the specified values for a field.
Example
extension.stack.ContentType('blog').containedIn('title', ['Demo', 'Welcome'])
Parameters:
Name Type Description
key String UID of the field
value * An array of values that are to be used to match or compare
Returns:
Type
Query

count() → {Query}

Source:
This method provides only the number of entries matching the specified filters.
Example
extension.stack.ContentType('blog').count()
Returns:
Type
Query

descending(key) → {Query}

Source:
This method sorts the entries in descending order on the basis of the specified field.
Example
extension.stack.ContentType('blog').descending('created_at')
Parameters:
Name Type Description
key String Field UID to be used for sorting
Returns:
Type
Query

environment(environment_uid) → {Query}

Source:
This method is used to set the environment name of which you want to retrieve the data.
Example
extension.stack.ContentType('contenttype_uid').Entry.Query().environment('development').find()
Parameters:
Name Type Description
environment_uid String UID/Name of environment
Returns:
Type
Query

equalTo(key, value) → {Query}

Source:
This method provides only the entries containing field values matching the specified condition.
Example
extension.stack.ContentType('blog').where('title','Demo')
Parameters:
Name Type Description
key String UID of the field
value * The value used to match or compare
Returns:
Type
Query

except(keyopt, values) → {Query}

Source:
This method is used to hide the selected fields of an entry in the result set.
Examples

Except with field uid

extension.stack.ContentType('content_type_uid').Entry.Query().except('title').find();

Except with field uid

extension.stack.ContentType('content_type_uid').Entry.Query().except('BASE','title').find();

Except with field uids(array)

extension.stack.ContentType('content_type_uid').Entry.Query().except(['title','description']).find();
Parameters:
Name Type Attributes Default Description
key String <optional>
BASE Single field of an entry
values Array Array of fields to be hidden in the result set
Returns:
Type
Query

exists(key) → {Query}

Source:
This method provides only the entries that contains the field matching the specified field UID.
Example
extension.stack.ContentType('blog').exists('featured')
Parameters:
Name Type Description
key String UID of the field
Returns:
Type
Query

find()

Source:
This method provides all the entries which satisfy the specified query.
Example
let blogQuery = extension.stack.ContentType('blog').find()

findOne()

Source:
This method provides a single entry from the result set.
Example
let blogQuery = extension.stack.ContentType('blog').findOne()

getQuery() → {Query}

returns Returns the raw query which can be used for further calls (.and/.or).

Source:
This method provides raw{json} queries based on the filters applied on the Query object.
Example
extension.stack.ContentType('blog').where('title','Demo').getQuery()
Returns:
Type
Query

greaterThan(key, value) → {Query}

Source:
This method provides only the entrieswith values greater than the specified value for a field.
Example
extension.stack.ContentType('blog').greaterThan('created_at','2015-03-12')
Parameters:
Name Type Description
key String UID of the field
value * The value used to match or compare
Returns:
Type
Query

greaterThanOrEqualTo(key, value) → {Query}

Source:
This method provides only the entries with values greater than or equal to the specified value for a field.
Example
extension.stack.ContentType('blog').greaterThanOrEqualTo('created_at', '2015-06-22')
Parameters:
Name Type Description
key String UID of the field
value * The value used to match or compare
Returns:
Type
Query

includeContentType() → {Query}

Source:
This method is used to include the current content type in the result set along with the entry(ies). Note: This method is only valid for querying Stack#ContentType#Entry.
Example
extension.stack.ContentType('contenttype_uid').Entry.Query().includeContentType().find()
Returns:
Type
Query

includeCount() → {Query}

Source:
This method also includes the total number of entries returned in the response.
Example
extension.stack.ContentType('blog').includeCount()
Returns:
Type
Query

includeOwner() → {Query}

Source:
This method is used to include the owner of the entry(ies) in the result set. Note: This method is only valid for querying Stack#ContentType#Entry.
Example
extension.stack.ContentType('contenttype_uid').Entry.Query().includeOwner().find()
Returns:
Type
Query

includeReference() → {Query}

Source:
This method is used to include referenced entries from other content types. Note: This method is only valid for querying Stack#ContentType#Entry.
Examples

.includeReference with reference_field_uids as array

stack.ContentType('contenttype_uid').Entry.Query().includeReference(['category', 'author']).find()

.includeReference with reference_field_uids

stack.ContentType('contenttype_uid').Entry.Query().includeReference('category', 'author').find()
Returns:
Type
Query

includeSchema() → {Query}

Source:
This method is used to include the schema of the current contenttype in result set along with the entry/entries. Note: This method is only valid for querying Stack#ContentType#Entry.
Example
extension.stack.ContentType('contenttype_uid').Entry.Query().includeSchema().find()
Returns:
Type
Query

language(languageCode) → {Query}

Source:
This method is used to set the language code of which you want to retrieve the data. Note: This method is only valid for querying Stack#ContentType#Entry.
Example
extension.stack.ContentType('contenttype_uid').Entry.Query().language('en-us').find()
Parameters:
Name Type Description
languageCode String Language code, for e.g. 'en-us', 'ja-jp', and so on
Returns:
Type
Query

limit(limit) → {Query}

Source:
This method limits the response by providing only the specified number of entries.
Example
extension.stack.ContentType('blog').limit(10)
Parameters:
Name Type Description
limit Number Maximum number of entries to be returned in the result.
Returns:
Type
Query

notContainedIn(key, value) → {Query}

Source:
This method provides only the entries that do not contain values matching the specified values for a field.
Example
extension.stack.ContentType('blog').notContainedIn('title', ['Demo', 'Welcome'])
Parameters:
Name Type Description
key String UID of the field
value Array An array of values that are to be used to match or compare
Returns:
Type
Query

notEqualTo(key, value) → {Query}

Source:
This method provides only the entries with values not equal to the specified value for a field.
Example
extension.stack.ContentType('blog').notEqualTo('title','Demo')
Parameters:
Name Type Description
key String UID of the field
value * The value used to match or compare
Returns:
Type
Query

notExists(key) → {Query}

Source:
This method provides only the entries that do not contain the field matching the specified field UID.
Example
extension.stack.ContentType('blog').notExists('featured')
Parameters:
Name Type Description
key String UID of the field
Returns:
Type
Query

only(keyopt, values) → {Query}

Source:
This method is used to show the selected fields of an entry in the result set.
Examples

Only with field UID

extension.stack.ContentType('content_type_uid').Entry.Query().only('title').find();

Only with field UID

extension.stack.ContentType('content_type_uid').Entry.Query().only('BASE','title').find();

Only with field UIDs(array)

extension.stack.ContentType('content_type_uid').Entry.Query().only(['title','description']).find();
Parameters:
Name Type Attributes Default Description
key String <optional>
BASE Single field of an entry
values Array Array of fields to be shown in the result set
Returns:
Type
Query

or(Array) → {Query}

Source:
This method performs the OR operation on the specified query objects and provides only the matching entries.
Examples

OR with query instances

let Query1 = extension.stack.ContentType('blog').Entry.Query().where('title', 'Demo')
let Query2 = extension.stack.ContentType('blog').Entry.Query().lessThan('comments', 10)
let blogQuery = extension.stack.ContentType('blog').or(Query1, Query2)

OR with query instances

let Query1 = extension.stack.ContentType('blog').Entry.Query().where('title', 'Demo').getQuery()
let Query2 = extension.stack.ContentType('blog').Entry.Query().lessThan('comments', 10).getQuery()
let blogQuery = extension.stack.ContentType('blog').or(Query1, Query2)
Parameters:
Name Type Description
Array object of query objects/raw queries to be taken into consideration
Returns:
Type
Query

query(query) → {Query}

Source:
This method is used to set raw queries on the Query instance.
Parameters:
Name Type Description
query object Raw{json} queries to filter the entries in the result set.
Returns:
Type
Query

regex(key, value, optionsopt) → {Query}

Source:
This method provides only the entries matching the regular expression for the specified field.
Examples

.regex without options

let blogQuery = extension.stack.ContentType('blog').regex('title','^Demo')

.regex with options

let blogQuery = extension.stack.ContentType('blog').regex('title','^Demo', 'i')
Parameters:
Name Type Attributes Description
key String UID of the field
value * The value used to match or compare
options String <optional>
Match or compare a value in the entry
Returns:
Type
Query
Source:
This method is used to search data in entries.
Example
extension.stack.ContentType('blog').search('Welcome to demo')
Parameters:
Name Type Description
value string Value to search in the entries.
Returns:
Type
Query

skip(skip) → {Query}

Source:
This method skips the specified number of entries.
Example
extension.stack.ContentType('blog').skip(5)
Parameters:
Name Type Description
skip Number Number of entries to be skipped
Returns:
Type
Query

tags(values) → {Query}

Source:
The ’tags’ parameter allows you to specify an array of tags to search for objects.
Example
extension.stack.ContentType('blog').tags(['technology', 'business'])
Parameters:
Name Type Description
values Array Tags
Returns:
Type
Query