# Class: Collection

## Collection

#### new Collection()

Creates a new collection. Collections store multiple documents and handle CRUD against those documents.

Source:
  - Collection.js, line 24

### Methods

- (static) collateAdd(collection, keyNameopt)
- (static) collateAdd(collection, process)
- (static) drop(removePersistent)
- (static) drop(removePersistent, callback)
- (static) drop(removePersistent)
- (static) drop(callback)
- (static) drop()
- (static) drop()
- (static) drop(callback)
- (static) drop(removePersistent, callback)
- (static) grid(selector, template, optionsopt) → {*}
- (static) isLinked() → {Boolean}
- (static) link(outputTargetSelector, templateSelector, optionsopt)
- (static) link(scope, varName, optionsopt, beforeAngularToForerunneropt)
- (static) link(scope, varName, optionsopt)
- (static) setData(data, options)
- (static) setData(data)
- (static) setData(data, options, callback)
- (static) setData(data, options, callback)
- (static) setData(data, callback)
- (static) setData(data, options, callback)
- (static) sync(objectType, objectName, query, callback)
- (static) sync(query, options, callback)
- (static) sync(collectionName, query, callback)
- (static) sync(objectType, objectName, callback)
- (static) sync(query, callback)
- (static) sync(objectType, objectName, query, options, callback)
- (static) sync(collectionName, callback)
- (static) sync(collectionName, query, options, callback)
- (static) sync(callback)
- (static) unGrid(selector, template, optionsopt) → {*}
- (static) unlink(outputTargetSelector, templateSelector)
- _insertHandle(data, indexopt, callbackopt)
- count() → {Number}
- data() → {Array}
- diff(collection) → {Object}
- distinct(path, queryopt, optionsopt) → {Array}
- drop(callbackopt) → {boolean}
- dropChart(selector)
- ensureIndex(keys, options) → {*}
- explain(query, optionsopt) → {Object}
- filter(queryopt, optionsopt, func) → {Array}
- filterUpdate(query, func, optionsopt) → {Array}
- find(query, optionsopt, callbackopt) → {Array}
- findById(id, optionsopt) → {Array}
- findOne() → {*}
- findSub(match, path, subDocQueryopt, subDocOptionsopt) → {*}
- findSubOne(match, path, subDocQueryopt, subDocOptionsopt) → {Object}
- group(groupObj, arr) → {Object}
- index(name) → {*}
- indexOf(query, optionsopt) → {Number}
- indexOfDocById(itemLookup, optionsopt) → {Number}
- init()
- insert(data, indexopt, callbackopt)
- insertIndexViolation(doc) → {Boolean}
- isProcessingQueue() → {Boolean}
- isSubsetOf(collection) → {Boolean}
- lastOp() → {Object}
- load(callbackopt)
- load(callbackopt)
- loadCustom(myData, callback)
- odm() → {Odm}
- options(objopt) → {Object}
- peek(search, optionsopt) → {Array}
- persistedSize(callback)
- primaryKey(keyNameopt) → {*}
- processQueue(type, callback, resultObjopt)
- remove(queryopt, optionsopt, callbackopt) → {Array}
- removeById(id) → {Object}
- removeByIndex(index) → {Object}
- save(callbackopt)
- save(callbackopt)
- saveCustom(callback)
- sort(sortObj, arr) → {Array}
- subset(query, optionsopt) → {*}
- transform(obj) → {*}
- transformIn(data) → {*}
- transformOut(data) → {*}
- truncate() → {Collection}
- unSync() → {boolean}
- update(query, update, optionsopt, callbackopt) → {Array}
- updateById(id, update, optionsopt, callbackopt) → {Object}
- upsert(obj, callbackopt) → {Array}
- view(name, query, options) → {*}
- when(query) → {Condition}

#### (static) collateAdd(collection, keyNameopt)

Adds a data source to collate data from and specifies the key name to collate data to.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`collection` | Collection |  | The collection to collate data from.
`keyName` | String | <optional> | Optional name of the key to collate data to. If none is provided the record CRUD is operated on the root collection data.

Source:
  - Collection.js, line 3616

#### (static) collateAdd(collection, process)

Adds a data source to collate data from and specifies a process method that will handle the collation functionality (for custom collation).

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | Collection | The collection to collate data from.
`process` | function | The process method.

Source:
  - Collection.js, line 3681

#### (static) drop(removePersistent)

Drop collection and optionally drop persistent storage.

##### Parameters:

Name | Type | Description
--- | --- | ---
`removePersistent` | Boolean | True to drop persistent storage, false to keep it.

Source:
  - NodePersist.js, line 498

#### (static) drop(removePersistent, callback)

Drop collections and optionally drop persistent storage with callback.

##### Parameters:

Name | Type | Description
--- | --- | ---
`removePersistent` | Boolean | True to drop persistent storage, false to keep it.
`callback` | function | Callback method.

Source:
  - Persist.js, line 669

#### (static) drop(removePersistent)

Drop collection and optionally drop persistent storage.

##### Parameters:

Name | Type | Description
--- | --- | ---
`removePersistent` | Boolean | True to drop persistent storage, false to keep it.

Source:
  - Persist.js, line 643

#### (static) drop(callback)

Drop collection and persistent storage with callback.

##### Parameters:

Name | Type | Description
--- | --- | ---
`callback` | function | Callback method.

Source:
  - Persist.js, line 631

#### (static) drop()

Drop collection and persistent storage.

Source:
  - Persist.js, line 620

#### (static) drop()

Drop collection and persistent storage.

Source:
  - NodePersist.js, line 475

#### (static) drop(callback)

Drop collection and persistent storage with callback.

##### Parameters:

Name | Type | Description
--- | --- | ---
`callback` | function | Callback method.

Source:
  - NodePersist.js, line 486

#### (static) drop(removePersistent, callback)

Drop collections and optionally drop persistent storage with callback.

##### Parameters:

Name | Type | Description
--- | --- | ---
`removePersistent` | Boolean | True to drop persistent storage, false to keep it.
`callback` | function | Callback method.

Source:
  - NodePersist.js, line 524

#### (static) grid(selector, template, optionsopt) → {*}

Creates a grid and assigns the collection as its data source.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`selector` | String |  | jQuery selector of grid output target.
`template` | String |  | The table template to use when rendering the grid.
`options` | Object | <optional> | The options object to apply to the grid.

Source:
  - Grid.js, line 561

##### Returns:

Type
  *

#### (static) isLinked() → {Boolean}

Checks if the instance is data-bound to any DOM elements.

Source:
  - AutoBind.js, line 46

##### Returns:

True if linked, false if not.

Type
  Boolean

#### (static) link(outputTargetSelector, templateSelector, optionsopt)

Creates a link to the DOM between the collection data and the elements in the passed output selector. When new elements are needed or changes occur the passed templateSelector is used to get the template that is output to the DOM.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`outputTargetSelector` |  |  |
`templateSelector` |  |  |
`options` | Object | <optional> | Optional extra options.

Source:
  - AutoBind.js, line 56
See:
  - unlink

#### (static) link(scope, varName, optionsopt, beforeAngularToForerunneropt)

Creates a link to the DOM between the collection data and the elements in the passed output selector. When new elements are needed or changes occur the passed templateSelector is used to get the template that is output to the DOM.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`scope` |  |  |
`varName` |  |  |
`options` | Object | <optional> | Optional extra options.
`beforeAngularToForerunner` | function | <optional> | Provides an optional function that allows you to modify data before angularJS updates ForerunnerDB with data from a view that has changed (like when a user edits a form element value that has been data-bound via ng-model).

Source:
  - Angular.js, line 28
See:
  - unlink

#### (static) link(scope, varName, optionsopt)

Creates a link to the DOM between the collection data and the elements in the passed output selector. When new elements are needed or changes occur the passed templateSelector is used to get the template that is output to the DOM.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`scope` |  |  |
`varName` |  |  |
`options` | Object | <optional> | Optional extra options.

Source:
  - Angular.js, line 146
See:
  - unlink

#### (static) setData(data, options)

Sets the collection's data to the array / documents passed. If any data already exists in the collection it will be removed before the new data is set via the remove() method, and the remove event will fire as well.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Array | Object | The array of documents or a single document that will be set as the collections data.
`options` | Object | Optional options object.

Source:
  - Collection.js, line 364

#### (static) setData(data)

Sets the collection's data to the array / documents passed. If any data already exists in the collection it will be removed before the new data is set via the remove() method, and the remove event will fire as well.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Array | Object | The array of documents or a single document that will be set as the collections data.

Source:
  - Collection.js, line 350

#### (static) setData(data, options, callback)

Sets the collection's data to the array / documents passed. If any data already exists in the collection it will be removed before the new data is set via the remove() method, and the remove event will fire as well.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Array | Object | The array of documents or a single document that will be set as the collections data.
`options` | * | Optional options object.
`callback` | * | Optional callback function.

Source:
  - Collection.js, line 410

#### (static) setData(data, options, callback)

Sets the collection's data to the array / documents passed. If any data already exists in the collection it will be removed before the new data is set via the remove() method, and the remove event will fire as well.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Array | Object | The array of documents or a single document that will be set as the collections data.
`options` | * | Optional options object.
`callback` | function | Optional callback function.

Source:
  - Collection.js, line 394

#### (static) setData(data, callback)

Sets the collection's data to the array / documents passed. If any data already exists in the collection it will be removed before the new data is set via the remove() method, and the remove event will fire as well.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Array | Object | The array of documents or a single document that will be set as the collections data.
`callback` | function | Optional callback function.

Source:
  - Collection.js, line 379

#### (static) setData(data, options, callback)

Sets the collection's data to the array / documents passed. If any data already exists in the collection it will be removed before the new data is set via the remove() method, and the remove event will fire as well.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Array | Object | The array of documents or a single document that will be set as the collections data.
`options` | Object | Optional options object.
`callback` | function | Optional callback function.

Source:
  - Collection.js, line 426

#### (static) sync(objectType, objectName, query, callback)

Sync with this collection on the server-side.

##### Parameters:

Name | Type | Description
--- | --- | ---
`objectType` | String | The type of object to sync to e.g. "collection" or "view".
`objectName` | String | The name of the object to sync from.
`query` | Object | A query object.
`callback` | function | The callback method to call once the connection to the server has been established.

Source:
  - NodeApiClient.js, line 480

#### (static) sync(query, options, callback)

Sync with this collection on the server-side.

##### Parameters:

Name | Type | Description
--- | --- | ---
`query` | Object | A query object.
`options` | Object | An options object.
`callback` | function | The callback method to call once the connection to the server has been established.

Source:
  - NodeApiClient.js, line 495

#### (static) sync(collectionName, query, callback)

Sync with this collection on the server-side.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collectionName` | String | The collection to sync from.
`query` | Object | A query object.
`callback` | function | The callback method to call once the connection to the server has been established.

Source:
  - NodeApiClient.js, line 467

#### (static) sync(objectType, objectName, callback)

Sync with this collection on the server-side.

##### Parameters:

Name | Type | Description
--- | --- | ---
`objectType` | String | The type of object to sync to e.g. "collection" or "view".
`objectName` | String | The name of the object to sync from.
`callback` | function | The callback method to call once the connection to the server has been established.

Source:
  - NodeApiClient.js, line 453

#### (static) sync(query, callback)

Sync with this collection on the server-side.

##### Parameters:

Name | Type | Description
--- | --- | ---
`query` | Object | A query object.
`callback` | function | The callback method to call once the connection to the server has been established.

Source:
  - NodeApiClient.js, line 441

#### (static) sync(objectType, objectName, query, options, callback)

Sync with this collection on the server-side.

##### Parameters:

Name | Type | Description
--- | --- | ---
`objectType` | String | The type of object to sync to e.g. "collection" or "view".
`objectName` | String | The name of the object to sync from.
`query` | Object | A query object.
`options` | Object | An options object.
`callback` | function | The callback method to call once the connection to the server has been established.

Source:
  - NodeApiClient.js, line 522

#### (static) sync(collectionName, callback)

Sync with this collection on the server-side.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collectionName` | String | The collection to sync from.
`callback` | function | The callback method to call once the connection to the server has been established.

Source:
  - NodeApiClient.js, line 429

#### (static) sync(collectionName, query, options, callback)

Sync with this collection on the server-side.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collectionName` | String | The collection to sync from.
`query` | Object | A query object.
`options` | Object | An options object.
`callback` | function | The callback method to call once the connection to the server has been established.

Source:
  - NodeApiClient.js, line 508

#### (static) sync(callback)

Sync with this collection on the server-side.

##### Parameters:

Name | Type | Description
--- | --- | ---
`callback` | function | The callback method to call once the connection to the server has been established.

Source:
  - NodeApiClient.js, line 418

#### (static) unGrid(selector, template, optionsopt) → {*}

Removes a grid safely from the DOM. Must be called when grid is no longer required / is being removed from DOM otherwise references will stick around and cause memory leaks.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`selector` | String |  | jQuery selector of grid output target.
`template` | String |  | The table template to use when rendering the grid.
`options` | Object | <optional> | The options object to apply to the grid.

Source:
  - Grid.js, line 597

##### Returns:

Type
  *

#### (static) unlink(outputTargetSelector, templateSelector)

Removes a link to the DOM between the collection data and the elements in the passed output selector that was created using the link() method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`outputTargetSelector` |  |
`templateSelector` |  |

Source:
  - AutoBind.js, line 186

#### _insertHandle(data, indexopt, callbackopt)

Inserts a document or array of documents into the collection.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`data` | Object | Array |  | Either a document object or array of document
`index` | Number | <optional> | Optional index to insert the record at.
`callback` | Collection.insertCallback | <optional> | Optional callback called once the insert is complete.

Source:
  - Collection.js, line 1834

#### count() → {Number}

Returns the number of documents currently in the collection.

Source:
  - Collection.js, line 3319

##### Returns:

Type
  Number

#### data() → {Array}

Get the data array that represents the collection's data. This data is returned by reference and should not be altered outside of the provided CRUD functionality of the collection as doing so may cause unstable index behaviour within the collection.

Source:
  - Collection.js, line 196

##### Returns:

Type
  Array

#### diff(collection) → {Object}

Generates a difference object that contains insert, update and remove arrays representing the operations to execute to make this collection have the same data as the one passed.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | Collection | The collection to diff against.

Source:
  - Collection.js, line 3552

##### Returns:

Type
  Object

#### distinct(path, queryopt, optionsopt) → {Array}

Find the distinct values for a specified field across a single collection and returns the values as a results array.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`path` | String |  | The field path to return distinct values for e.g. "person.name".
`query` | Object | <optional> | The query to use to filter the documents used to return values from.
`options` | Object | <optional> | The query options to use when running the query.

Source:
  - Collection.js, line 2157

##### Returns:

Type
  Array

#### drop(callbackopt) → {boolean}

Drops a collection and all it's stored data from the database.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`callback` | function | <optional> | A callback method to call once the operation has completed.

Source:
  - Collection.js, line 206

##### Returns:

True on success, false on failure.

Type
  boolean

#### dropChart(selector)

Removes a chart from the page by it's selector.

##### Parameters:

Name | Type | Description
--- | --- | ---
`selector` | String | The chart selector.

Source:
  - Highchart.js, line 658

#### ensureIndex(keys, options) → {*}

Creates an index on the specified keys.

##### Parameters:

Name | Type | Description
--- | --- | ---
`keys` | Object | The object containing keys to index.
`options` | Object | An options object.

Source:
  - Collection.js, line 3455

##### Returns:

Type
  *

#### explain(query, optionsopt) → {Object}

Provides a query plan / operations log for a query.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`query` | Object |  | The query to execute.
`options` | Object | <optional> | Optional options object.

Source:
  - Collection.js, line 2240

##### Returns:

The query plan.

Type
  Object

#### filter(queryopt, optionsopt, func) → {Array}

Executes a method against each document that matches query and returns an array of documents that may have been modified by the method.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`query` | Object | <optional> | The optional query object.
`options` | Object | <optional> | Optional options object. If you specify an options object you MUST also specify a query object.
`func` | function |  | The method that each document is passed to. If this method returns false for a particular document it is excluded from the results. If you return a modified object from the one passed to it will be included in the results as the modified version but will not affect the data in the collection at all. Your function will be called with a single object as the first argument and will be called once for every document in your initial query result.

Source:
  - Collection.js, line 708

##### Returns:

Type
  Array

#### filterUpdate(query, func, optionsopt) → {Array}

Executes a method against each document that matches query and then executes an update based on the return data of the method.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`query` | Object |  | The query object.
`func` | function |  | The method that each document is passed to. If this method returns false for a particular document it is excluded from the update.
`options` | Object | <optional> | Optional options object passed to the initial find call.

Source:
  - Collection.js, line 738

##### Returns:

Type
  Array

#### find(query, optionsopt, callbackopt) → {Array}

Queries the collection based on the query object passed.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`query` | Object |  | The query key/values that a document must match in order for it to be returned in the result array.
`options` | Object | <optional> | An optional options object.
`callback` | function | <optional> | !! DO NOT USE, THIS IS NON-OPERATIONAL !! Optional callback. If specified the find process will not return a value and will assume that you wish to operate under an async mode. This will break up large find requests into smaller chunks and process them in a non-blocking fashion allowing large datasets to be queried without causing the browser UI to pause. Results from this type of operation will be passed back to the callback once completed.

Source:
  - Collection.js, line 2276

##### Returns:

The results array from the find operation, containing all documents that matched the query.

Type
  Array

#### findById(id, optionsopt) → {Array}

Helper method to find a document by it's id.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`id` | String |  | The id of the document.
`options` | Object | <optional> | The options object, allowed keys are sort and limit.

Source:
  - Collection.js, line 2192

##### Returns:

The items that were updated.

Type
  Array

#### findOne() → {*}

Returns one document that satisfies the specified query criteria. If multiple documents satisfy the query, this method returns the first document to match the query.

Source:
  - Collection.js, line 2709

##### Returns:

Type
  *

#### findSub(match, path, subDocQueryopt, subDocOptionsopt) → {*}

Finds sub-documents from the collection's documents.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`match` | Object |  | The query object to use when matching parent documents from which the sub-documents are queried.
`path` | String |  | The path string used to identify the key in which sub-documents are stored in parent documents.
`subDocQuery` | Object | <optional> | The query to use when matching which sub-documents to return.
`subDocOptions` | Object | <optional> | The options object to use when querying for sub-documents.

Source:
  - Collection.js, line 3340

##### Returns:

Type
  *

#### findSubOne(match, path, subDocQueryopt, subDocOptionsopt) → {Object}

Finds the first sub-document from the collection's documents that matches the subDocQuery parameter.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`match` | Object |  | The query object to use when matching parent documents from which the sub-documents are queried.
`path` | String |  | The path string used to identify the key in which sub-documents are stored in parent documents.
`subDocQuery` | Object | <optional> | The query to use when matching which sub-documents to return.
`subDocOptions` | Object | <optional> | The options object to use when querying for sub-documents.

Source:
  - Collection.js, line 3410

##### Returns:

Type
  Object

#### group(groupObj, arr) → {Object}

Groups an array of documents into multiple array fields, named by the value of the given group path.

##### Parameters:

Name | Type | Description
--- | --- | ---
`groupObj` | * | The key path the array objects should be grouped by.
`arr` | Array | The array of documents to group.

Source:
  - Collection.js, line 2940

##### Returns:

Type
  Object

#### index(name) → {*}

Gets an index by it's name.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | The name of the index to retreive.

Source:
  - Collection.js, line 3531

##### Returns:

Type
  *

#### indexOf(query, optionsopt) → {Number}

Gets the index in the collection data array of the first item matched by the passed query object.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`query` | Object |  | The query to run to find the item to return the index of.
`options` | Object | <optional> | An options object.

Source:
  - Collection.js, line 2720

##### Returns:

Type
  Number

#### indexOfDocById(itemLookup, optionsopt) → {Number}

Returns the index of the document identified by the passed item's primary key.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`itemLookup` | * |  | The document whose primary key should be used to lookup or the id to lookup.
`options` | Object | <optional> | An options object.

Source:
  - Collection.js, line 2747

##### Returns:

The index the item with the matching primary key is occupying.

Type
  Number

#### init()

Creates a new collection. Collections store multiple documents and handle CRUD against those documents.

Source:
  - Collection.js, line 32

#### insert(data, indexopt, callbackopt)

Inserts a document or array of documents into the collection.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`data` | Object | Array |  | Either a document object or array of document
`index` | Number | <optional> | Optional index to insert the record at.
`callback` | Collection.insertCallback | <optional> | Optional callback called once the insert is complete.

Source:
  - Collection.js, line 1798

#### insertIndexViolation(doc) → {Boolean}

Checks that the passed document will not violate any index rules if inserted into the collection.

##### Parameters:

Name | Type | Description
--- | --- | ---
`doc` | Object | The document to check indexes against.

Source:
  - Collection.js, line 3421

##### Returns:

Either false (no violation occurred) or true if a violation was detected.

Type
  Boolean

#### isProcessingQueue() → {Boolean}

Checks if any CRUD operations have been deferred and are still waiting to be processed.

Source:
  - Collection.js, line 1777

##### Returns:

True if there are still deferred CRUD operations to process or false if all queues are clear.

Type
  Boolean

#### isSubsetOf(collection) → {Boolean}

Checks if the collection is a subset of the passed collection.

##### Parameters:

Name | Type | Description
--- | --- | ---
`collection` | Collection | The collection to test against.

Source:
  - Collection.js, line 2145

##### Returns:

True if the passed collection is the parent of the current collection.

Type
  Boolean

#### lastOp() → {Object}

Gets the last reporting operation's details such as run time.

Source:
  - Collection.js, line 3541

##### Returns:

Type
  Object

#### load(callbackopt)

Loads an entire collection's data from persistent storage.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`callback` | function | <optional> | The method to call when the load function has completed.

Source:
  - Persist.js, line 791

#### load(callbackopt)

Loads an entire collection's data from persistent storage.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`callback` | function | <optional> | The method to call when the load function has completed.

Source:
  - NodePersist.js, line 612

#### loadCustom(myData, callback)

Loads custom data loaded by a third-party plugin into the collection.

##### Parameters:

Name | Type | Description
--- | --- | ---
`myData` | Object | Data object previously saved by using saveCustom()
`callback` | function | A callback method to receive notification when data has loaded.

Source:
  - Persist.js, line 896

#### odm() → {Odm}

Get the ODM instance for this collection.

Source:
  - Odm.js, line 166

##### Returns:

Type
  Odm

#### options(objopt) → {Object}

Generates an options object with default values or adds default values to a passed object if those values are not currently set to anything.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`obj` | Object | <optional> | Optional options object to modify.

Source:
  - Collection.js, line 2252

##### Returns:

The options object.

Type
  Object

#### peek(search, optionsopt) → {Array}

Finds all documents that contain the passed string or search object regardless of where the string might occur within the document. This will match strings from the start, middle or end of the document's string (partial match).

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`search` | String |  | The string to search for. Case sensitive.
`options` | Object | <optional> | A standard find() options object.

Source:
  - Collection.js, line 2207

##### Returns:

An array of documents that matched the search string.

Type
  Array

#### persistedSize(callback)

Determines the byte size of a persisted collection

##### Parameters:

Name | Type | Description
--- | --- | ---
`callback` | persistedSizeCallback | The method to call when the size check is complete

Source:
  - Persist.js, line 769

#### primaryKey(keyNameopt) → {*}

Gets / sets the primary key for this collection.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`keyName` | String | <optional> | The name of the primary key.

Source:
  - Collection.js, line 257

##### Returns:

Type
  *

#### processQueue(type, callback, resultObjopt)

Processes a deferred action queue.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`type` | String |  | The queue name to process.
`callback` | function |  | A method to call when the queue has processed.
`resultObj` | Object | <optional> | A temp object to hold results in.

Source:
  - Collection.js, line 1721

#### remove(queryopt, optionsopt, callbackopt) → {Array}

Removes any documents from the collection that match the search query key/values.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`query` | Object | <optional> | The query identifying the documents to remove. If no query object is passed, all documents will be removed from the collection.
`options` | Object | <optional> | An options object.
`callback` | function | <optional> | A callback method.

Source:
  - Collection.js, line 1603

##### Returns:

An array of the documents that were removed.

Type
  Array

#### removeById(id) → {Object}

Helper method that removes a document that matches the given id.

##### Parameters:

Name | Type | Description
--- | --- | ---
`id` | String | The id of the document to remove.

Source:
  - Collection.js, line 1709

##### Returns:

The document that was removed or undefined if nothing was removed.

Type
  Object

#### removeByIndex(index) → {Object}

Removes a document from the collection by it's index in the collection's data array.

##### Parameters:

Name | Type | Description
--- | --- | ---
`index` | Number | The index of the document to remove.

Source:
  - Collection.js, line 2780

##### Returns:

The document that has been removed or false if none was removed.

Type
  Object

#### save(callbackopt)

Saves an entire collection's data to persistent storage.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`callback` | function | <optional> | The method to call when the save function has completed.

Source:
  - Persist.js, line 709

#### save(callbackopt)

Saves an entire collection's data to persistent storage.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`callback` | function | <optional> | The method to call when the save function has completed.

Source:
  - NodePersist.js, line 562

#### saveCustom(callback)

Gets the data that represents this collection for easy storage using a third-party method / plugin instead of using the standard persistent storage system.

##### Parameters:

Name | Type | Description
--- | --- | ---
`callback` | function | The method to call with the data response.

Source:
  - Persist.js, line 837

#### sort(sortObj, arr) → {Array}

Sorts an array of documents by the given sort path.

##### Parameters:

Name | Type | Description
--- | --- | ---
`sortObj` | * | The keys and orders the array objects should be sorted by.
`arr` | Array | The array of documents to sort.

Source:
  - Collection.js, line 2899

##### Returns:

Type
  Array

#### subset(query, optionsopt) → {*}

Uses the passed query to generate a new collection with results matching the query parameters.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`query` | Object |  | The query object to generate the subset with.
`options` | Object | <optional> | An options object.

Source:
  - Collection.js, line 2118

##### Returns:

Type
  *

#### transform(obj) → {*}

Gets / sets the collection transform options.

##### Parameters:

Name | Type | Description
--- | --- | ---
`obj` | Object | A collection transform options object.

Source:
  - Collection.js, line 2801

##### Returns:

Type
  *

#### transformIn(data) → {*}

Transforms data using the set transformIn method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Object | The data to transform.

Source:
  - Collection.js, line 2834

##### Returns:

Type
  *

#### transformOut(data) → {*}

Transforms data using the set transformOut method.

##### Parameters:

Name | Type | Description
--- | --- | ---
`data` | Object | The data to transform.

Source:
  - Collection.js, line 2866

##### Returns:

Type
  *

#### truncate() → {Collection}

Clears all data from the collection.

Source:
  - Collection.js, line 555

##### Returns:

Type
  Collection

#### unSync() → {boolean}

Disconnects an existing connection to a sync server.

Source:
  - NodeApiClient.js, line 563

##### Returns:

True if a connection existed, false if no connection existed.

Type
  boolean

#### update(query, update, optionsopt, callbackopt) → {Array}

Modifies an existing document or documents in a collection. This will update all matches for 'query' with the data held in 'update'. It will not overwrite the matched documents with the update document.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`query` | Object |  | The query that must be matched for a document to be operated on.
`update` | Object |  | The object containing updated key/values. Any keys that match keys on the existing document will be overwritten with this data. Any keys that do not currently exist on the document will be added to the document.
`options` | Object | <optional> | An options object.
`callback` | function | <optional> | The callback method to call when the update is complete.

Source:
  - Collection.js, line 779

##### Returns:

The items that were updated.

Type
  Array

#### updateById(id, update, optionsopt, callbackopt) → {Object}

Helper method to update a document via it's id.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`id` | String |  | The id of the document.
`update` | Object |  | The object containing the key/values to update to.
`options` | Object | <optional> | An options object.
`callback` | function | <optional> | The callback method to call when the update is complete.

Source:
  - Collection.js, line 977

##### Returns:

The document that was updated or undefined if no document was updated.

Type
  Object

#### upsert(obj, callbackopt) → {Array}

Inserts a new document or updates an existing document in a collection depending on if a matching primary key exists in the collection already or not. If the document contains a primary key field (based on the collections's primary key) then the database will search for an existing document with a matching id. If a matching document is found, the document will be updated. Any keys that match keys on the existing document will be overwritten with new data. Any keys that do not currently exist on the document will be added to the document. If the document does not contain an id or the id passed does not match an existing document, an insert is performed instead. If no id is present a new primary key id is provided for the document and the document is inserted.

##### Parameters:

Name | Type | Attributes | Description
--- | --- | --- | ---
`obj` | Object |  | The document object to upsert or an array containing documents to upsert.
`callback` | function | <optional> | Optional callback method.

Source:
  - Collection.js, line 616

##### Returns:

An array containing an object for each operation performed. Each object contains two keys, "op" contains either "none", "insert" or "update" depending on the type of operation that was performed and "result" contains the return data from the operation used.

Type
  Array

#### view(name, query, options) → {*}

Creates a view and assigns the collection as its data source.

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | String | The name of the new view.
`query` | Object | The query to apply to the new view.
`options` | Object | The options object to apply to the view.

Source:
  - View.js, line 1466

##### Returns:

Type
  *

#### when(query) → {Condition}

Creates a condition handler that will react to changes in data on the collection.

##### Parameters:

Name | Type | Description
--- | --- | ---
`query` | Object | The query that will trigger the condition's then() callback.

Source:
  - Collection.js, line 3750
See:
  - Condition

##### Returns:

Type
  Condition

##### Example

    Create a condition handler that reacts when data changes.
    	var coll = db.collection('test'),
    		condition = coll.when({_id: 'test1', val: 1})
    		.then(function () {
    			console.log('Condition met!');
    	 	})
    	 	.else(function () {
    	 		console.log('Condition un-met');
    	 	});

    	 	coll.insert({_id: 'test1', val: 1});

### Members

- areaChart :Overload
- barChart :Overload
- columnChart :Overload
- lineChart :Overload
- pieChart :Overload
- stackedBarChart :Overload

#### areaChart :Overload

Creates an area chart from the collection.

##### Type:

- Overload

Source:
  - Highchart.js, line 453

#### barChart :Overload

Creates a bar chart from the collection.

##### Type:

- Overload

Source:
  - Highchart.js, line 553

#### columnChart :Overload

Creates a column chart from the collection.

##### Type:

- Overload

Source:
  - Highchart.js, line 503

#### lineChart :Overload

Creates a line chart from the collection.

##### Type:

- Overload

Source:
  - Highchart.js, line 392

#### pieChart :Overload

Creates a pie chart from the collection.

##### Type:

- Overload

Source:
  - Highchart.js, line 342

#### stackedBarChart :Overload

Creates a stacked bar chart from the collection.

##### Type:

- Overload

Source:
  - Highchart.js, line 603

### Type Definitions

#### insertCallback(result)

The insert operation's callback.

##### Parameters:

Name | Type | Description
--- | --- | ---
`result` | Object | The result object will contain two arrays (inserted and failed) which represent the documents that did get inserted and those that didn't for some reason (usually index violation). Failed items also contain a reason. Inspect the failed array for further information. A third field called "deferred" is a boolean value to indicate if the insert operation was deferred across more than one CPU cycle (to avoid blocking the main thread).

Source:
  - Collection.js, line 1813