Class: Resultset

Resultset(collection)

new Resultset(collection)

Resultset class allowing chainable queries. Intended to be instanced internally. Collection.find(), Collection.where(), and Collection.chain() instantiate this.

Parameters:
Name Type Description
collection Collection

The collection which this Resultset will query against.

Source:
Example
mycollection.chain()
     .find({ 'doors' : 4 })
     .where(function(obj) { return obj.name === 'Toyota' })
     .data();

Members

branch

Alias of copy()

Source:

Methods

compoundsort(properties) → {Resultset}

Allows sorting a resultset based on multiple columns.

Parameters:
Name Type Description
properties array

array of property names or subarray of [propertyname, isdesc] used evaluate sort order

Source:
Returns:

Reference to this resultset, sorted, for future chain operations.

Type
Resultset
Example
// to sort by age and then name (both ascending)
rs.compoundsort(['age', 'name']);
// to sort by age (ascending) and then by name (descending)
rs.compoundsort(['age', ['name', true]);

copy() → {Resultset}

copy() - To support reuse of resultset in branched query situations.

Source:
Returns:

Returns a copy of the resultset (set) but the underlying document references will be the same.

Type
Resultset

count() → {number}

count() - returns the number of documents in the resultset.

Source:
Returns:

The number of documents in the resultset.

Type
number

data(optionsopt) → {array}

Terminates the chain and returns array of filtered documents

Parameters:
Name Type Attributes Description
options object <optional>

allows specifying 'forceClones' and 'forceCloneMethod' options.

Properties
Name Type Description
forceClones boolean

Allows forcing the return of cloned objects even when the collection is not configured for clone object.

forceCloneMethod string

Allows overriding the default or collection specified cloning method. Possible values include 'parse-stringify', 'jquery-extend-deep', 'shallow', 'shallow-assign'

removeMeta bool

Will force clones and strip $loki and meta properties from documents

Source:
Returns:

Array of documents in the resultset

Type
array

eqJoin(joinData, leftJoinKey, rightJoinKey, mapFunopt, dataOptionsopt) → {Resultset}

eqJoin() - Left joining two sets of data. Join keys can be defined or calculated properties eqJoin expects the right join key values to be unique. Otherwise left data will be joined on the last joinData object with that key

Parameters:
Name Type Attributes Description
joinData Array | Resultset | Collection

Data array to join to.

leftJoinKey string | function

Property name in this result set to join on or a function to produce a value to join on

rightJoinKey string | function

Property name in the joinData to join on or a function to produce a value to join on

mapFun function <optional>

(Optional) A function that receives each matching pair and maps them into output objects - function(left,right){return joinedObject}

dataOptions object <optional>

options to data() before input to your map function

Properties
Name Type Description
removeMeta bool

allows removing meta before calling mapFun

forceClones boolean

forcing the return of cloned objects to your map object

forceCloneMethod string

Allows overriding the default or collection specified cloning method.

Source:
Returns:

A resultset with data in the format [{left: leftObj, right: rightObj}]

Type
Resultset

find(query, firstOnlyopt) → {Resultset}

Used for querying via a mongo-style query object.

Parameters:
Name Type Attributes Description
query object

A mongo-style query object used for filtering current results.

firstOnly boolean <optional>

(Optional) Used by collection.findOne()

Source:
Returns:

this resultset for further chain ops.

Type
Resultset

limit(qty) → {Resultset}

Allows you to limit the number of documents passed to next chain operation. A resultset copy() is made to avoid altering original resultset.

Parameters:
Name Type Description
qty int

The number of documents to return.

Source:
Returns:

Returns a copy of the resultset, limited by qty, for subsequent chain ops.

Type
Resultset

map(mapFun, dataOptionsopt)

Applies a map function into a new collection for further chaining.

Parameters:
Name Type Attributes Description
mapFun function

javascript map function

dataOptions object <optional>

options to data() before input to your map function

Properties
Name Type Description
removeMeta bool

allows removing meta before calling mapFun

forceClones boolean

forcing the return of cloned objects to your map object

forceCloneMethod string

Allows overriding the default or collection specified cloning method.

Source:

mapReduce(mapFunction, reduceFunction) → {value}

data transformation via user supplied functions

Parameters:
Name Type Description
mapFunction function

this function accepts a single document for you to transform and return

reduceFunction function

this function accepts many (array of map outputs) and returns single value

Source:
Returns:

The output of your reduceFunction

Type
value

offset(pos) → {Resultset}

Used for skipping 'pos' number of documents in the resultset.

Parameters:
Name Type Description
pos int

Number of documents to skip; all preceding documents are filtered out.

Source:
Returns:

Returns a copy of the resultset, containing docs starting at 'pos' for subsequent chain ops.

Type
Resultset

remove() → {Resultset}

Removes all document objects which are currently in resultset from collection (as well as resultset)

Source:
Returns:

this (empty) resultset for further chain ops.

Type
Resultset

simplesort(propname, isdescopt) → {Resultset}

Simpler, loose evaluation for user to sort based on a property name. (chainable). Sorting based on the same lt/gt helper functions used for binary indices.

Parameters:
Name Type Attributes Description
propname string

name of property to sort by.

isdesc bool <optional>

(Optional) If true, the property will be sorted in descending order

Source:
Returns:

Reference to this resultset, sorted, for future chain operations.

Type
Resultset

sort(comparefun) → {Resultset}

User supplied compare function is provided two documents to compare. (chainable)

Parameters:
Name Type Description
comparefun function

A javascript compare function used for sorting.

Source:
Returns:

Reference to this resultset, sorted, for future chain operations.

Type
Resultset
Example
rslt.sort(function(obj1, obj2) {
     if (obj1.name === obj2.name) return 0;
     if (obj1.name > obj2.name) return 1;
     if (obj1.name < obj2.name) return -1;
   });

transform(transform, parametersopt) → {Resultset}

transform() - executes a named collection transform or raw array of transform steps against the resultset.

Parameters:
Name Type Attributes Description
transform string | array

name of collection transform or raw transform array

parameters object <optional>

(Optional) object property hash of parameters, if the transform requires them.

Source:
Returns:

either (this) resultset or a clone of of this resultset (depending on steps)

Type
Resultset

update(updateFunction) → {Resultset}

Used to run an update operation on all documents currently in the resultset.

Parameters:
Name Type Description
updateFunction function

User supplied updateFunction(obj) will be executed for each document object.

Source:
Returns:

this resultset for further chain ops.

Type
Resultset

where(fun) → {Resultset}

where() - Used for filtering via a javascript filter function.

Parameters:
Name Type Description
fun function

A javascript function used for filtering current results by.

Source:
Returns:

this resultset for further chain ops.

Type
Resultset