Optional
options: Partial<CollectionOptions>Alias of LokiEventEmitter.prototype.on addListener(eventName, listener) - adds a listener to the queue of callbacks associated to an event
the index of the callback in the array of listeners for a particular event
LokiEventEmitter
the name(s) of the event(s) to listen to
callback function of listener to attach
boolean determines whether or not the callbacks associated with each event should happen in an async fashion or not Default is false, which means events are synchronous
LokiEventEmitter
a collection of objects recording the changes applied through a commmitStage
a hashmap, with each property being an array of callbacks
LokiEventEmitter
stages: a map of uniquely identified 'stages', which hold copies of objects to be manipulated without affecting the data in the original collection
Optional
age?: numberOptional
daemon?: TimerOptional
ttlAdaptively remove a selected item from the index.
: coll.data array index/position
: index to search for dataPosition in
Optional
removedFromIndexOnly: booleanAdd a dynamic view to the collection
reference to the dynamic view added
var pview = users.addDynamicView('progeny');
pview.applyFind({'age': {'$lte': 40}});
pview.applySimpleSort('name');
var results = pview.data();
Optional
name: stringname of dynamic view to add
Optional
options: Partial<DynamicViewOptions>options to configure dynamic view with
Adds a named collection transform to the collection
users.addTransform('progeny', [
{
type: 'find',
value: {
'age': {'$lte': 40}
}
}
]);
var results = users.chain('progeny').data();
name to associate with transform
an array of transformation 'step' objects to save into the collection
calculateRange() - Binary Search utility method to find range/segment of values matching criteria. this is used for collection.find() and first find filter of resultset/dynview slightly different than get() binary search in that get() hones in on 1 value, but we have to hone in on many (range)
[start, end] index array positions
operation, such as $eq
name of property to calculate range for
value to use for range calculation.
Internal method used for indexed $between. Given a prop (index name), and a value (which may or may not yet exist) this will find the final position of that upper range value.
Internal method used for index maintenance and indexed searching. Calculates the beginning of an index range for a given value. For index maintainance (adaptive:true), we will return a valid index position to insert to. For querying (adaptive:false/undefined), we will : return lower bound/index of range of that value (if found) return next lower index position if not found (hole) If index is empty it is assumed to be handled at higher level, so this method assumes there is at least 1 document in index.
name of property which has binary index
value to find within index
if true, we will return insert position
Optional
usingDotNotation: booleanChain method, used for beginning a series of chained find() and/or view() operations on a collection.
(this) resultset, or data array if any map or join functions where called
Optional
transform: ChainTransformnamed transform or array of transform steps
Optional
parameters: anyObject containing properties representing parameters to substitute
Perform checks to determine validity/consistency of all binary indices
array of index names where problems were found.
// check all indices on a collection, returns array of invalid index names
var result = coll.checkAllIndexes({ repair: true, randomSampling: true, randomSamplingFactor: 0.15 });
if (result.length > 0) {
results.forEach(function(name) {
console.log('problem encountered with index : ' + name);
});
}
Optional
options: { optional configuration object
whether (faster) random sampling should be used
percentage of total rows to randomly sample
whether to fix problems if they are encountered
Perform checks to determine validity/consistency of a binary index
whether the index was found to be valid (before optional correcting).
// full test
var valid = coll.checkIndex('name');
// full test with repair (if issues found)
valid = coll.checkIndex('name', { repair: true });
// random sampling (default is 10% of total document count)
valid = coll.checkIndex('name', { randomSampling: true });
// random sampling (sample 20% of total document count)
valid = coll.checkIndex('name', { randomSampling: true, randomSamplingFactor: 0.20 });
// random sampling (implied boolean)
valid = coll.checkIndex('name', { randomSamplingFactor: 0.20 });
// random sampling with repair (if issues found)
valid = coll.checkIndex('name', { repair: true, randomSampling: true });
name of the binary-indexed property to check
optional configuration object
Optional
randomwhether (faster) random sampling should be used
Optional
randompercentage of total rows to randomly sample
Optional
repair?: booleanwhether to fix problems if they are encountered
Empties the collection of all data but leaves indexes and options intact by default.
Optional
options: { configure clear behavior
Optional
removewhether to remove indices in addition to data
Will allow reconfiguring certain collection options.
Optional
adaptivecollection indices will be actively rebuilt rather than lazily
Optional
old: Temit(eventName, data) - emits a particular event with the option of passing optional parameters which are going to be processed by the callback provided signatures match (i.e. if passing emit(event, arg0, arg1) the listener should take two parameters)
LokiEventEmitter
the name of the event
Optional
data: unknownoptional object passed with the event
Optional
arg: anyJoin two collections on specified properties
Result of the mapping operation
array of documents to 'join' to this collection
property name in collection
property name in joinData
(Optional) map function to use
options to data() before input to your map function
Allows overriding the default or collection specified cloning method.
forcing the return of cloned objects to your map object
allows removing meta before calling mapFun
Find method, api is similar to mongodb. for more complex queries use [chain()]chain or [where()]where.
{@tutorial Query Examples}
Array of matching documents
Optional
query: Record<string, any>'mongo-like' query object
Applies a 'mongo-like' find query object and passes all results to an update function. For filter function querying you should migrate to [updateWhere()]updateWhere.
'mongo-like' query object (or deprecated filterFunction mode)
update function to run against filtered documents
Get by Id - faster than other methods because of the searching algorithm
Object reference if document was found, null if not, or an array if 'returnPosition' was passed.
$loki id of document you want to retrieve
Optional
returnPosition: booleanif 'true' we will return [object, position]
Perform binary range lookup for the data[dataPosition][binaryIndexName] property value Since multiple documents may contain the same value (which the index is sorted on), we hone in on range and then linear scan range to find exact index array position.
: coll.data array index/position
: index to search for dataPosition in
Look up dynamic view reference from within the collection
A reference to the dynamic view with that name
name of dynamic view to retrieve reference of
(Staging API) create a stage and/or retrieve it
Returns a named unique index
indexed field name
Optional
force: booleanif true
, will rebuild index; otherwise, function may return null
Adds object(s) to collection, ensure object(s) have meta properties, clone it if necessary, etc.
document or documents inserted
users.insert({
name: 'Odin',
age: 50,
address: 'Asgard'
});
// alternatively, insert array of documents
users.insert([{ name: 'Thor', age: 35}, { name: 'Loki', age: 30}]);
the document (or array of documents) to be inserted
Optional
overrideAdaptiveIndices: boolean(optional) if true
, adaptive indicies will be
temporarily disabled and then fully rebuilt after batch. This will be faster for
large inserts, but slower for small/medium inserts in large collections
Adds a single object, ensures it has meta properties, clone it if necessary, etc.
document or 'undefined' if there was a problem inserting it
the document to be inserted
Optional
bulkInsert: booleanquiet pre-insert and insert event emits
on(eventName, listener) - adds a listener to the queue of callbacks associated to an event
the index of the callback in the array of listeners for a particular event
LokiEventEmitter
the name(s) of the event(s) to listen to
callback function of listener to attach
Remove a document from the collection
CollectionDocument | null - null if document not found, otherwise removed document. Array of new documents is not returned
Internal method called by remove()
array of documents or $loki ids to remove
removeListener() - removes the listener at position 'index' from the event 'eventName'
LokiEventEmitter
the name(s) of the event(s) which the listener is attached to
the listener callback function to remove from emitter
Rest
...args: any[]Remove all documents matching supplied filter function. For 'mongo-like' querying you should migrate to [findAndRemove()]findAndRemove.
query object to filter on
Updates a named collection transform to the collection
name to associate with transform
a transformation object to save into collection
(Staging API) create a copy of an object and insert it into a stage
Updates an object and notifies collection that the document has changed.
the document that was updated
document to update within the collection
Query the collection by supplying a javascript filter function.
var results = coll.where(function(obj) {
return obj.legs === 8;
});
all documents which pass your filter function
filter function to run against all collection docs
Generated using TypeDoc
Collection class that handles documents of same type
Implements
SylvieEventEmitter
Param
collection name
Param
(optional) array of property names to be indicized OR a configuration object
Param
array of property names to define unique constraints for
Param
array of property names to define exact constraints for
Param
array property names to define binary indexes for
Param
collection indices will be actively rebuilt rather than lazily
Param
whether listeners are invoked asynchronously
Param
set to true to disable meta property on documents
Param
set to false to enable Changes API
Param
set to false to enable Delta Changes API (requires Changes API, forces cloning)
Param
use Object.observe to update objects automatically
Param
specify whether inserts and queries clone to/from user
Param
converts date values on binary indexed properties to epoch time
Param
when false all docs are frozen
Param
'parse-stringify', 'jquery-extend-deep', 'shallow', 'shallow-assign'
Param
age of document (in ms.) before document is considered aged/stale.
Param
time interval for clearing out 'aged' documents; not set by default.
See
Sylvie#addCollection for normal creation of collections