Class: Collection

Collection

new Collection(name, optionsopt)

Collection class that handles documents of same type

Parameters:
Name Type Attributes Description
name string

collection name

options array | object <optional>

(optional) array of property names to be indicized OR a configuration object

Properties
Name Type Description
unique array

array of property names to define unique constraints for

exact array

array of property names to define exact constraints for

indices array

array property names to define binary indexes for

adaptiveBinaryIndices boolean

collection indices will be actively rebuilt rather than lazily (default: true)

asyncListeners boolean

default is false

disableChangesApi boolean

default is true

autoupdate boolean

use Object.observe to update objects automatically (default: false)

clone boolean

specify whether inserts and queries clone to/from user

cloneMethod string

'parse-stringify' (default), 'jquery-extend-deep', 'shallow'

ttlInterval int

time interval for clearing out 'aged' documents; not set by default.

Implements:
Source:
See:

Methods

addDynamicView(name, optionsopt) → {DynamicView}

Add a dynamic view to the collection

Parameters:
Name Type Attributes Description
name string

name of dynamic view to add

options object <optional>

(optional) options to configure dynamic view with

Properties
Name Type Description
persistent boolean

indicates if view is to main internal results array in 'resultdata'

sortPriority string

'passive' (sorts performed on call to data) or 'active' (after updates)

minRebuildInterval number

minimum rebuild interval (need clarification to docs here)

Source:
Returns:

reference to the dynamic view added

Type
DynamicView

addTransform(name, transform)

Adds a named collection transform to the collection

Parameters:
Name Type Description
name string

name to associate with transform

transform array

an array of transformation 'step' objects to save into the collection

Source:

avg(field) → {number}

Calculates the average numerical value of a property

Parameters:
Name Type Description
field string

name of property in docs to average

Source:
Returns:

average of property in all docs in the collection

Type
number

by(field, value) → {object}

Retrieve doc by Unique index

Parameters:
Name Type Description
field string

name of uniquely indexed property to use when doing lookup

value value

unique value to search for

Source:
Returns:

document matching the value passed

Type
object

chain(transform, parameters) → {Resultset}

Chain method, used for beginning a series of chained find() and/or view() operations on a collection.

Parameters:
Name Type Description
transform array

Ordered array of transform step objects similar to chain

parameters object

Object containing properties representing parameters to substitute

Source:
Returns:

(this) resultset, or data array if any map or join functions where called

Type
Resultset

clear()

Empties the collection.

Source:

commitStage(stageName, message)

(Staging API) re-attach all objects to the original collection, so indexes and views can be rebuilt then create a message to be inserted in the commitlog

Parameters:
Name Type Description
stageName string

name of stage

message string
Source:

configureOptions()

Will allow reconfiguring certain collection options.

Parameters:
Name Type Description
options.adaptiveBinaryIndices boolean

collection indices will be actively rebuilt rather than lazily

Source:

count(queryopt) → {number}

Quickly determine number of documents in collection (or query)

Parameters:
Name Type Attributes Description
query object <optional>

(optional) query object to count results of

Source:
Returns:

number of documents in the collection

Type
number

ensureIndex(property, forceopt)

Ensure binary index on a certain field

Parameters:
Name Type Attributes Description
property string

name of property to create binary index on

force boolean <optional>

(Optional) flag indicating whether to construct index immediately

Source:

eqJoin(joinData, leftJoinProp, rightJoinProp, mapFunopt) → {Resultset}

Join two collections on specified properties

Parameters:
Name Type Attributes Description
joinData array

array of documents to 'join' to this collection

leftJoinProp string

property name in collection

rightJoinProp string

property name in joinData

mapFun function <optional>

(Optional) map function to use

Source:
Returns:

Result of the mapping operation

Type
Resultset

extract()

Source:

extractNumerical()

Source:

find(query) → {array}

Find method, api is similar to mongodb. for more complex queries use chain() or where().

Parameters:
Name Type Description
query object

'mongo-like' query object

Source:
Returns:

Array of matching documents

Type
array
Example
Query Examples

findAndRemove(filterObject)

Applies a 'mongo-like' find query object removes all documents which match that filter.

Parameters:
Name Type Description
filterObject object

'mongo-like' query object

Source:

findAndUpdate(filterObject, updateFunction)

Applies a 'mongo-like' find query object and passes all results to an update function. For filter function querying you should migrate to updateWhere().

Parameters:
Name Type Description
filterObject object | function

'mongo-like' query object (or deprecated filterFunction mode)

updateFunction function

update function to run against filtered documents

Source:

findOne(query) → {object|null}

Find one object by index property, by property equal to value

Parameters:
Name Type Description
query object

query object used to perform search with

Source:
Returns:

First matching document, or null if none

Type
object | null

get(id, returnPosition) → {object|array|null}

Get by Id - faster than other methods because of the searching algorithm

Parameters:
Name Type Description
id int

$loki id of document you want to retrieve

returnPosition boolean

if 'true' we will return [object, position]

Source:
Returns:

Object reference if document was found, null if not, or an array if 'returnPosition' was passed.

Type
object | array | null

getDynamicView(name) → {DynamicView}

Look up dynamic view reference from within the collection

Parameters:
Name Type Description
name string

name of dynamic view to retrieve reference of

Source:
Returns:

A reference to the dynamic view with that name

Type
DynamicView

getStage()

(Staging API) create a stage and/or retrieve it

Source:

insert(doc) → {object|array}

Adds object(s) to collection, ensure object(s) have meta properties, clone it if necessary, etc.

Parameters:
Name Type Description
doc object | array

the document (or array of documents) to be inserted

Source:
Returns:

document or documents inserted

Type
object | array

insertOne(doc, bulkInsert) → {object}

Adds a single object, ensures it has meta properties, clone it if necessary, etc.

Parameters:
Name Type Description
doc object

the document to be inserted

bulkInsert boolean

quiet pre-insert and insert event emits

Source:
Returns:

document or 'undefined' if there was a problem inserting it

Type
object

mapReduce(mapFunction, reduceFunction) → {data}

Map Reduce operation

Parameters:
Name Type Description
mapFunction function

function to use as map function

reduceFunction function

function to use as reduce function

Source:
Returns:

The result of your mapReduce operation

Type
data

max()

Source:

maxRecord()

Source:

median(field)

Parameters:
Name Type Description
field string

property name

Source:

min()

Source:

minRecord()

Source:

mode(field)

Parameters:
Name Type Description
field string
Source:

remove(doc)

Remove a document from the collection

Parameters:
Name Type Description
doc object

document to remove from collection

Source:

removeDynamicView(name)

Remove a dynamic view from the collection

Parameters:
Name Type Description
name string

name of dynamic view to remove

Source:

removeTransform(name)

Removes a named collection transform from the collection

Parameters:
Name Type Description
name string

name of collection transform to remove

Source:

removeWhere(query)

Remove all documents matching supplied filter function. For 'mongo-like' querying you should migrate to findAndRemove().

Parameters:
Name Type Description
query function | object

query object to filter on

Source:

setTransform(name, transform)

Updates a named collection transform to the collection

Parameters:
Name Type Description
name string

name to associate with transform

transform object

a transformation object to save into collection

Source:

stage()

(Staging API) create a copy of an object and insert it into a stage

Source:

stdDev(field)

Calculate standard deviation of a field

Parameters:
Name Type Description
field string
Source:

update(doc)

Updates an object and notifies collection that the document has changed.

Parameters:
Name Type Description
doc object

document to update within the collection

Source:

updateWhere(filterFunction, updateFunction)

Applies a filter function and passes all results to an update function.

Parameters:
Name Type Description
filterFunction function

filter function whose results will execute update

updateFunction function

update function to run against filtered documents

Source:

where(fun) → {array}

Query the collection by supplying a javascript filter function.

Parameters:
Name Type Description
fun function

filter function to run against all collection docs

Source:
Returns:

all documents which pass your filter function

Type
array
Example
var results = coll.where(function(obj) {
  return obj.legs === 8;
});