API Reference

Query Class

Defined in lib/query.js:19

Description

The query constructor.

Warehouse uses a MongoDB-like way to query documents.

Logical operators

You can use an array of two or more expressions in logical operators. For example:

query.find({
$or: [{comments: true}, {published: false}]
});
  • $or - Performs a logical OR operation
  • $and - Performs a logical AND operation
  • $not - Performs a logical NOT operation
  • $nor - Performs a logical NOR operation

Constructor

Query

(index)
Defined in lib/query.js:19

The query constructor.

Warehouse uses a MongoDB-like way to query documents.

Logical operators

You can use an array of two or more expressions in logical operators. For example:

query.find({
$or: [{comments: true}, {published: false}]
});
  • $or - Performs a logical OR operation
  • $and - Performs a logical AND operation
  • $not - Performs a logical NOT operation
  • $nor - Performs a logical NOR operation

Parameters

Methods

_createQuery

(index) Query private
Defined in lib/query.js:80

Creates a new query.

Parameters

Returns

_query

(data, conditions) Boolean private
Defined in lib/query.js:425

Checks if the data matches the conditions.

Parameters

Returns

count

Number
Defined in lib/query.js:145

Returns the number of documents in the query.

Returns

each

(iterator) chainable
Defined in lib/query.js:119

Alias for Query.forEach

Parameters

eq

(num) Document
Defined in lib/query.js:238

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

Parameters

Returns

filter

(callback) Query
Defined in lib/query.js:603

Iterates over the query and returns all elements the callback returns truey for.

Parameters

Returns

find

(conditions, [options]) Query
Defined in lib/query.js:519

Finds the matching documents in the query.

Parameters

Returns

findOne

(conditions) Document
Defined in lib/query.js:542

Finds the first matching document.

Parameters

Returns

first

Document
Defined in lib/query.js:254

Returns the first document in the query.

This method is an alias of:

query.eq(0);

Returns

forEach

(iterator) chainable
Defined in lib/query.js:99

Iterates over the query.

Parameters

last

Document
Defined in lib/query.js:271

Returns the last item in the model.

This method is an alias of:

query.eq(-1);

Returns

limit

(num) Query
Defined in lib/query.js:301

Limits the number of items returned.

This method is an alias of:

query.slice(0, num);

Parameters

Returns

map

(callback) Array
Defined in lib/query.js:568

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

Parameters

Returns

populate

(name) chainable
Defined in lib/query.js:554

Sets the path to populate.

Parameters

random

Query
Defined in lib/query.js:406

Returns the documents in the query in random order.

Returns

reduce

(callback, [initial]) Any
Defined in lib/query.js:579

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

Parameters

  • callback Function
  • initial Any optional

    Initial value

Returns

  • Any

reduceRight

(callback, [initial]) Any
Defined in lib/query.js:591

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

Parameters

  • callback Function
  • initial Any optional

    Initial value

Returns

  • Any

remove

([callback]) chainable
Defined in lib/query.js:214

Removes all documents in the query.

Parameters

replace

(obj, [callback]) chainable
Defined in lib/query.js:189

Replaces all documents in the query.

Parameters

reverse

Query
Defined in lib/query.js:337

Returns the query in reversed order.

Returns

shuffle

Query
Defined in lib/query.js:417

Alias for Query.random

Returns

size

Number
Defined in lib/query.js:156

Alias for Query.count

Returns

skip

(num) Query
Defined in lib/query.js:319

Specifies the number of items to skip.

This method is an alias of:

query.slice(num);

Parameters

Returns

slice

(start, [end]) Query
Defined in lib/query.js:288

Returns the specified range of documents in the query.

Parameters

Returns

sort

(orderby, [order]) Query
Defined in lib/query.js:348

Sorts the documents in the query.

Example:

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

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

Parameters

Returns

toArray

Array
Defined in lib/query.js:128

Returns an array containing all documents in the query.

Returns

update

(obj, [callback]) chainable
Defined in lib/query.js:164

Updates all documents in the query.

Parameters

Properties

_index

private
Defined in lib/query.js:46

The index of the query.

_populates

private
Defined in lib/query.js:56

The fields to populate.

length

Defined in lib/query.js:66

Returns the number of items in the query.