API Reference

Model Class

Defined in lib/model.js:27

Description

The model constructor.

Constructor

Model

(name, schema, database)
Defined in lib/model.js:27

The model constructor.

Parameters

Methods

_applyGetter

(obj, name, value, [prefix]) Object private
Defined in lib/model.js:219

Applies the schema.

Parameters

Returns

_applySetter

(obj, name, value, [prefix]) Object private
Defined in lib/model.js:392

Applies the schema.

Parameters

Returns

_checkID

(id) Boolean private
Defined in lib/model.js:194

Checks if id is used.

Parameters

Returns

_createQuery

([index]) Query private
Defined in lib/model.js:179

Creates a new query.

Parameters

Returns

_getRaw

(id) Object private
Defined in lib/model.js:316

Finds raw data of a single document by id.

Parameters

Returns

_populate

(obj, populates) Object private
Defined in lib/model.js:981

Popluates document references.

Parameters

Returns

_save

(obj, callback) private
Defined in lib/model.js:474

Saves a document to the model.

Parameters

_update

(data, obj) Object private
Defined in lib/model.js:581

Combines the old and the new data.

Parameters

Returns

_updateIndex

private
Defined in lib/model.js:161

Updates the index.

count

Number
Defined in lib/model.js:373

Returns the number of items in the model.

Returns

destroy

chainable
Defined in lib/model.js:794

Deletes all documents in the model.

each

(iterator) chainable
Defined in lib/model.js:347

Alias for Model.forEach

Parameters

eq

(num) Document
Defined in lib/model.js:808

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

Parameters

Returns

filter

(callback) Query
Defined in lib/model.js:1072

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

Parameters

Returns

find

(conditions, [options]) Query
Defined in lib/model.js:954

Finds the matching documents in the model.

See Query/find

Parameters

Returns

findById

(id) Document
Defined in lib/model.js:307

Alias for Model.get

Parameters

Returns

findOne

(conditions) Document
Defined in lib/model.js:969

Finds the first matching document.

Parameters

Returns

first

Document
Defined in lib/model.js:824

Returns the first document in the model.

This method is an alias of:

model.eq(0);

Returns

forEach

(iterator) chainable
Defined in lib/model.js:329

Iterates over the model.

Parameters

get

(id) Document
Defined in lib/model.js:283

Finds a single document by id.

Parameters

Returns

insert

(obj, [callback]) chainable
Defined in lib/model.js:519

Inserts a document to the model.

Parameters

last

Document
Defined in lib/model.js:841

Returns the last document in the model.

This method is an alias of:

model.eq(-1);

Returns

limit

(num) Query
Defined in lib/model.js:871

Limits the number of items returned.

This method is an alias of:

model.slice(0, num);

Parameters

Returns

map

(callback) Array
Defined in lib/model.js:1037

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

Parameters

Returns

new

(obj) Document
Defined in lib/model.js:207

Creates a new document.

Parameters

Returns

populate

(name) Query
Defined in lib/model.js:1025

Sets the path to populate.

Parameters

Returns

random

Query
Defined in lib/model.js:935

Returns the documents in the model in random order.

Returns

reduce

(callback, [initial]) Any
Defined in lib/model.js:1048

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/model.js:1060

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

(conditions, [callback]) chainable
Defined in lib/model.js:708

Removes documents matching the conditions in the model.
conditions can be either a query object or the id of the document.

Parameters

removeById

(id, [callback]) chainable
Defined in lib/model.js:728

Removes a document in the model by id.

Parameters

replace

(conditions, obj, [callback]) chainable
Defined in lib/model.js:661

Replaces documents matching the conditions in the model.
conditions can be either a query object or the id of the document.

Parameters

replaceById

(id, obj, [callback]) chainable
Defined in lib/model.js:682

Replaces a document in the model by id.

Parameters

reverse

Query
Defined in lib/model.js:907

Returns the model in reversed order.

Returns

save

(obj, [callback]) chainable
Defined in lib/model.js:775

Saves a document to the model.

Parameters

shuffle

Query
Defined in lib/model.js:946

Alias for Model.random

Returns

size

Number
Defined in lib/model.js:384

Alias for Model.count

Returns

skip

(num) Query
Defined in lib/model.js:889

Specifies the number of items to skip.

This method is an alias of:

`` js model.slice(num);

Parameters

Returns

slice

(start, [end]) Query
Defined in lib/model.js:858

Returns the specified range of documents in the model.

Parameters

Returns

sort

(orderby, [order]) Query
Defined in lib/model.js:918

Sorts the documents in the model.

See Query/sort

Parameters

Returns

toArray

Array
Defined in lib/model.js:356

Returns an array containing all items in the model.

Returns

update

(conditions, obj, [callback]) chainable
Defined in lib/model.js:560

Updates documents matching the conditions in the model.
conditions can be either a query object or the id of the document.

Parameters

updateById

(id, obj, [callback]) chainable
Defined in lib/model.js:627

Updates a document in the model by id.

Parameters

Properties

_database

private
Defined in lib/model.js:51

The reference to the database.

_doc

private
Defined in lib/model.js:97

The document constructor.

_index

private
Defined in lib/model.js:73

The index of the model.

_name

private
Defined in lib/model.js:41

The name of the model.

_query

private
Defined in lib/model.js:119

The query constructor.

_store

private
Defined in lib/model.js:61

Reference the store in the database as lazy-loaded getter.

length

Defined in lib/model.js:137

Returns the number of items in the model.

schema

private
Defined in lib/model.js:83

The schema of the model.

Events

init

Defined in lib/model.js:150

Fires when the model initialized.

insert

(result)
Defined in lib/model.js:547

Fires when a document inserted.

Parameters

remove

(doc)
Defined in lib/model.js:755

Fires when a document removed.

Parameters

update

(result)
Defined in lib/model.js:648

Fires when a document updated.

Parameters