new Resultset(collection, optionsopt)
Resultset class allowing chainable queries. Intended to be instanced internally. Collection.find(), Collection.where(), and Collection.chain() instantiate this.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
collection |
Collection | The collection which this Resultset will query against. |
|||||||||||||
options |
Object |
<optional> |
Object containing one or more options. Properties
|
Example
mycollection.chain()
.find({ 'doors' : 4 })
.where(function(obj) { return obj.name === 'Toyota' })
.data();
Members
branch
Alias of copy()
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 |
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.
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.
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
|
Returns:
Array of documents in the resultset
- Type
- array
eqJoin(joinData, leftJoinKey, rightJoinKey, mapFunopt) → {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 | 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} |
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() |
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. |
Returns:
Returns a copy of the resultset, limited by qty, for subsequent chain ops.
- Type
- Resultset
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 |
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. |
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)
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 |
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. |
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. |
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. |
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. |
Returns:
this resultset for further chain ops.
- Type
- Resultset