Query

Query

new Query(data)

Query constructor.

Parameters:
Name Type Description
data Array
Source:

Methods

count()

Returns the number of elements.

Source:
Returns:

Number

eq(i) → {Document|Object}

Returns the document at the specified index. num can be a positive or negative number.

Parameters:
Name Type Description
i Number
Source:
Returns:
Type
Document | Object

every(iterator) → {Boolean}

Tests whether all documents pass the test implemented by the provided function.

Parameters:
Name Type Description
iterator function
Source:
Returns:
Type
Boolean

filter(iterator) → {Query}

Creates a new array with all documents that pass the test implemented by the provided function.

Parameters:
Name Type Description
iterator function
Source:
Returns:
Type
Query

find(query, optionsopt) → {Query|Array}

Finds matching documents.

Parameters:
Name Type Attributes Description
query Object
options Object <optional>
Properties
Name Type Attributes Default Description
limit Number <optional>
0

Limits the number of documents returned.

skip Number <optional>
0

Skips the first elements.

lean Boolean <optional>
false

Returns a plain JavaScript object.

Source:
Returns:
Type
Query | Array

findOne(query, optionsopt) → {Document|Object}

Finds the first matching documents.

Parameters:
Name Type Attributes Description
query Object
options Object <optional>
Properties
Name Type Attributes Default Description
skip Number <optional>
0

Skips the first elements.

lean Boolean <optional>
false

Returns a plain JavaScript object.

Source:
Returns:
Type
Document | Object

first() → {Document|Object}

Returns the first document.

Source:
Returns:
Type
Document | Object

forEach(iterator)

Iterates over all documents.

Parameters:
Name Type Description
iterator function
Source:

last() → {Document|Object}

Returns the last document.

Source:
Returns:
Type
Document | Object

limit(i) → {Query}

Limits the number of documents returned.

Parameters:
Name Type Description
i Number
Source:
Returns:
Type
Query

map(iterator) → {Array}

Creates an array of values by iterating each element in the collection.

Parameters:
Name Type Description
iterator function
Source:
Returns:
Type
Array

populate(expr) → {Query}

Populates document references.

Parameters:
Name Type Description
expr String | Object
Source:
Returns:
Type
Query

reduce(iterator, initialopt) → {*}

Reduces a collection to a value which is the accumulated result of iterating each element in the collection.

Parameters:
Name Type Attributes Description
iterator function
initial * <optional>

By default, the initial value is the first document.

Source:
Returns:
Type
*

reduceRight(iterator, initialopt) → {*}

Reduces a collection to a value which is the accumulated result of iterating each element in the collection from right to left.

Parameters:
Name Type Attributes Description
iterator function
initial * <optional>

By default, the initial value is the last document.

Source:
Returns:
Type
*

remove(callbackopt) → {Promise}

Remove all documents.

Parameters:
Name Type Attributes Description
callback function <optional>
Source:
Returns:
Type
Promise

replace(data, callbackopt) → {Promise}

Replace all documents.

Parameters:
Name Type Attributes Description
data Object
callback function <optional>
Source:
Returns:
Type
Promise

reverse() → {Query}

Returns documents in a reversed order.

Source:
Returns:
Type
Query

shuffle() → {Query}

Returns documents in random order.

Source:
Returns:
Type
Query

skip(i) → {Query}

Specifies the number of items to skip.

Parameters:
Name Type Description
i Number
Source:
Returns:
Type
Query

slice(start, endopt) → {Query}

Returns the specified range of documents.

Parameters:
Name Type Attributes Description
start Number
end Number <optional>
Source:
Returns:
Type
Query

some(iterator) → {Boolean}

Tests whether some documents pass the test implemented by the provided function.

Parameters:
Name Type Description
iterator function
Source:
Returns:
Type
Boolean

sort(orderby, orderopt) → {Query}

Sorts documents.

Example:

query.sort('date', -1);
query.sort({date: -1, title: 1});
query.sort('-date title');

If the order equals to -1, desc or descending, the data will be returned in reversed order.

Parameters:
Name Type Attributes Description
orderby String | Object
order String | Number <optional>
Source:
Returns:
Type
Query

toArray() → {Array}

Returns an array containing all documents.

Source:
Returns:
Type
Array

update(data, callbackopt) → {Promise}

Update all documents.

Parameters:
Name Type Attributes Description
data Object
callback function <optional>
Source:
Returns:
Type
Promise