Collection <T>
Hierarchy
- Target<[typeof CollectionDocumentPreInsertEventName, typeof CollectionDocumentInsertEventName, typeof CollectionDocumentPreUpdateEventName, typeof CollectionDocumentUpdateEventName, typeof CollectionDocumentDeleteEventName, typeof ErrorEventName, typeof WarnEventName]>
- Collection
Index
Constructors
Properties
- adaptiveBinaryIndices
- asyncListeners
- autoupdate
- binaryIndices
- changes
- cloneMethod
- cloneObjects
- commitLog
- constraints
- createStack
- createTime
- data
- dirty
- disableChangesApi
- disableDeltaChangesApi
- disableFreeze
- disableMeta
- dynamicViews
- fire
- idIndex
- isIncremental
- maxId
- name
- objType
- off
- on
- options
- sd
- serializableIndices
- stages
- transactional
- transforms
- ttl
- uniqueNames
Methods
- adaptiveBinaryIndexInsert
- adaptiveBinaryIndexRemove
- adaptiveBinaryIndexUpdate
- add
- addAutoUpdateObserver
- addDynamicView
- addEventListener
- addTransform
- by
- byExample
- calculateRange
- calculateRangeStart
- chain
- checkAllIndexes
- checkIndex
- clear
- commitStage
- configureOptions
- count
- createChange
- createInsertChange
- createUpdateChange
- dispatchEvent
- ensureAllIndexes
- ensureId
- ensureIdAsync
- ensureIndex
- ensureUniqueIndex
- eqJoin
- extract
- extractNumerical
- find
- findAndRemove
- findAndUpdate
- findObject
- findObjects
- findOne
- findOneUnIndexed
- flushChanges
- get
- getBinaryIndexPosition
- getBinaryIndexValues
- getChangeDelta
- getChanges
- getDynamicView
- getObjectDelta
- getStage
- getTransform
- getUniqueIndex
- insert
- insertMeta
- insertMetaWithChange
- insertOne
- mapReduce
- max
- maxRecord
- mean
- median
- min
- minRecord
- mode
- observerCallback
- prepareFullDocIndex
- remove
- removeBatchByPositions
- removeDataOnly
- removeDynamicView
- removeEventListener
- removeTransform
- removeWhere
- rollback
- setChangesApi
- setTTL
- setTransform
- stage
- standardDeviation
- ttlDaemonFuncGen
- update
- updateMeta
- updateMetaWithChange
- updateWhere
- where
Constructors
constructor
Type parameters
- T
Parameters
name: string = 'Collection'
optionaloptions: Partial<ICollectionOptions<T>>
Returns Collection<T>
Properties
adaptiveBinaryIndices
if set to true we will optimally keep indices ‘fresh’ during insert/update/remove ops (never dirty/never needs rebuild) if you frequently intersperse insert/update/remove ops between find ops this will likely be significantly faster option.
asyncListeners
option to make event listeners async, default is sync
autoupdate
option to observe objects and update them automatically, ignored if
Object.observe is not supported
binaryIndices
user defined indexes, this field supports dot notation
changes
changes are tracked by collection and aggregated by the db
cloneMethod
default clone method (if enabled) is parse-stringify
cloneObjects
options to clone objects when inserting them
commitLog
a collection of objects recording the changes applied through a commit stage
constraints
Type declaration
exact: Record<string, ExactIndex<string>>
unique: any
createStack
createTime
data
the data held by the collection
dirty
in autosave scenarios we will use collection level dirty flags to determine whether save is needed. Currently, if any collection is dirty we will autosave the whole database if autosave is configured. defaulting to true since this is called from addCollection and adding a collection should trigger save.
disableChangesApi
disable track changes
disableDeltaChangesApi
disable delta update object style on changes
readonlydisableFreeze
option to deep freeze all documents
readonlydisableMeta
if set to true we will not maintain a meta property for a document
dynamicViews
fire
Type declaration
Type parameters
- T: EventName<ICollectionDocumentPreInsertEventDetail<any>> | EventName<ICollectionDocumentInsertEventDetail<any>> | EventName<ICollectionDocumentPreUpdateEventDetail<any>> | EventName<ICollectionDocumentUpdateEventDetail<any>> | EventName<ICollectionDocumentDeleteEventDetail<any>> | EventName<IErrorEventDetail>
Parameters
event: Event<EventDetail<T>>
Returns boolean
idIndex
position->$loki index (built lazily)
isIncremental
maxId
currentMaxId - change manually at your own peril!
publicname
objType
the object type of the collection
off
Type declaration
Type parameters
- T: EventName<ICollectionDocumentPreInsertEventDetail<any>> | EventName<ICollectionDocumentInsertEventDetail<any>> | EventName<ICollectionDocumentPreUpdateEventDetail<any>> | EventName<ICollectionDocumentUpdateEventDetail<any>> | EventName<ICollectionDocumentDeleteEventDetail<any>> | EventName<IErrorEventDetail>
Parameters
type: EventName<T>
callback: Listener<T>
optionaloptions: boolean | EventListenerOptions
Returns void
on
Type declaration
Type parameters
- T: EventName<ICollectionDocumentPreInsertEventDetail<any>> | EventName<ICollectionDocumentInsertEventDetail<any>> | EventName<ICollectionDocumentPreUpdateEventDetail<any>> | EventName<ICollectionDocumentUpdateEventDetail<any>> | EventName<ICollectionDocumentDeleteEventDetail<any>> | EventName<IErrorEventDetail>
Parameters
type: T
listener: Listener<T>
optionaloptions: boolean | AddEventListenerOptions
Returns void
options
sd
Type declaration
Type parameters
- K: string | number | symbol
Parameters
field: K
Returns number
readonlyserializableIndices
by default, if you insert a document into a collection with binary indices, if those indexed properties contain a DateTime we will convert to epoch time format so that (across serializations) its value position will be the same ‘after’ serialization as it was ‘before’.
stages
stages: a map of uniquely identified ‘stages’, which hold copies of objects to be manipulated without affecting the data in the original collection
transactional
is collection transactional
transforms
transforms will be used to store frequently used query chains as a series of steps which itself can be stored along with the database.
readonlyttl
option to activate a cleaner daemon - clears ‘aged’ documents at set intervals.
uniqueNames
unique constraints contain duplicate object references, so they are not persisted. we will keep track of properties which have unique constraint applied here, and regenerate lazily.
Methods
adaptiveBinaryIndexInsert
Adaptively insert a selected item to the index.
Type parameters
- K: ValidSimpleLensField
- D: boolean
Parameters
dataPosition: number
: coll.data array index/position
binaryIndexName: K
: index to search for dataPosition in
optionalusingDotNotation: D
Returns void
adaptiveBinaryIndexRemove
Adaptively remove a selected item from the index.
Parameters
dataPosition: number | number[]
coll.data array index/position
binaryIndexName: keyof T
index to search for dataPosition in
optionalremovedFromIndexOnly: boolean
Returns any
adaptiveBinaryIndexUpdate
Adaptively update a selected item within an index.
Parameters
dataPosition: number
coll.data array index/position
binaryIndexName: ValidSimpleLensField
index to search for dataPosition in
Returns void
add
Add object to collection
Parameters
document: T
Returns any
addAutoUpdateObserver
Parameters
object: T & ICollectionDocument
Returns void
addDynamicView
Add a dynamic view to the collection
Parameters
name: string = ''
name of dynamic view to add
optionaloptions: Partial<IDynamicViewOptions>
options to configure dynamic view with
Returns DynamicView<T>
addEventListener
Type parameters
- T: EventName<any, T>
Parameters
type: T
listener: Listener<T>
optionaloptions: boolean | AddEventListenerOptions
Returns void
addTransform
Adds a named collection transform to the collection
Type parameters
- R0
- R1
Parameters
name: string
name to associate with transform
transform: TransformRequest<T, R0, R1>[]
an array of transformation ‘step’ objects to save into the collection
Returns void
by
Retrieve doc by Unique index
Type parameters
- K: string | number | symbol
Parameters
field: K
name of uniquely indexed property to use when doing lookup
optionalvalue: T[K]
unique value to search for
Returns any
document matching the value passed
byExample
Parameters
template: Partial<{ [ Key in string | number | symbol ]: DotNotationValue<T, Key> | Partial<{ $aeq: DotNotationValue<T, Key>; $between: DotNotationValue<T, Key> extends number ? [number, number] : never; $contains: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsAny: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsNone: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsString: DotNotationValue<T, Key> extends string ? string : never; $definedin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $dteq: DotNotationValue<T, Key> extends string | number | Date ? Date : never; $elemMatch: DotNotationValue<T, Key> extends ArrayLike<E> ? E extends object ? Partial<{ [Key in DotNotation<E>]: DotNotationValue<E, Key> | Partial<{ $size: DotNotationValue<E, Key> extends Set<any> | ArrayLike<...> ? number : never; ... 32 more ...; $exists: unknown; }>; }> : never : never; $eq: DotNotationValue<T, Key>; $exists: unknown; $finite: DotNotationValue<T, Key> extends number ? boolean : never; $gt: DotNotationValue<T, Key> extends number ? number : never; $gte: DotNotationValue<T, Key> extends number ? number : never; $in: DotNotationValue<T, Key>[]; $inSet: Set<DotNotationValue<T, Key>>; $jbetween: DotNotationValue<T, Key> extends number ? [number, number] : never; $jgt: DotNotationValue<T, Key> extends number ? number : never; $jgte: DotNotationValue<T, Key> extends number ? number : never; $jlt: DotNotationValue<T, Key> extends number ? number : never; $jlte: DotNotationValue<T, Key> extends number ? number : never; $keyin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $len: DotNotationValue<T, Key> extends ArrayLike<any> ? number : never; $lt: DotNotationValue<T, Key> extends number ? number : never; $lte: DotNotationValue<T, Key> extends number ? number : never; $ne: DotNotationValue<T, Key>; $nin: DotNotationValue<T, Key>[]; $nkeyin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $not: Partial<{ [Key in DotNotation<DotNotationValue<T, Key>>]: DotNotationValue<DotNotationValue<T, Key>, Key> | Partial<...>; }>; $regex: DotNotationValue<T, Key> extends string ? RegExp : never; $size: DotNotationValue<T, Key> extends Set<any> | ArrayLike<any> ? number : never; $type: Type; $undefinedin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $where: (x: DotNotationValue<T, Key>) => boolean }> }>
Returns Partial<{ [ Key in string | number | symbol ]: DotNotationValue<T, Key> | Partial<{ $aeq: DotNotationValue<T, Key>; $between: DotNotationValue<T, Key> extends number ? [number, number] : never; $contains: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsAny: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsNone: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsString: DotNotationValue<T, Key> extends string ? string : never; $definedin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $dteq: DotNotationValue<T, Key> extends string | number | Date ? Date : never; $elemMatch: DotNotationValue<T, Key> extends ArrayLike<E> ? E extends object ? Partial<{ [Key in DotNotation<E>]: DotNotationValue<E, Key> | Partial<{ $size: DotNotationValue<E, Key> extends Set<any> | ArrayLike<...> ? number : never; ... 32 more ...; $exists: unknown; }>; }> : never : never; $eq: DotNotationValue<T, Key>; $exists: unknown; $finite: DotNotationValue<T, Key> extends number ? boolean : never; $gt: DotNotationValue<T, Key> extends number ? number : never; $gte: DotNotationValue<T, Key> extends number ? number : never; $in: DotNotationValue<T, Key>[]; $inSet: Set<DotNotationValue<T, Key>>; $jbetween: DotNotationValue<T, Key> extends number ? [number, number] : never; $jgt: DotNotationValue<T, Key> extends number ? number : never; $jgte: DotNotationValue<T, Key> extends number ? number : never; $jlt: DotNotationValue<T, Key> extends number ? number : never; $jlte: DotNotationValue<T, Key> extends number ? number : never; $keyin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $len: DotNotationValue<T, Key> extends ArrayLike<any> ? number : never; $lt: DotNotationValue<T, Key> extends number ? number : never; $lte: DotNotationValue<T, Key> extends number ? number : never; $ne: DotNotationValue<T, Key>; $nin: DotNotationValue<T, Key>[]; $nkeyin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $not: Partial<{ [Key in DotNotation<DotNotationValue<T, Key>>]: DotNotationValue<DotNotationValue<T, Key>, Key> | Partial<...>; }>; $regex: DotNotationValue<T, Key> extends string ? RegExp : never; $size: DotNotationValue<T, Key> extends Set<any> | ArrayLike<any> ? number : never; $type: Type; $undefinedin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $where: (x: DotNotationValue<T, Key>) => boolean }> }>
calculateRange
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/dynamicView slightly different than get() binary search in that get() hones in on 1 value, but we have to hone in on many (range)
Type parameters
- P: ValidSimpleLensField
- D: boolean
Parameters
operation: $size | $eq | $aeq | $ne | $dteq | $gt | $gte | $lt | $lte | $jgt | $jgte | $jlt | $jlte | $between | $jbetween | $in | $inSet | $nin | $keyin | $nkeyin | $definedin | $undefinedin | $regex | $containsString | $containsAny | $containsNone | $contains | $elemMatch | $type | $finite | $len | $where | $not | $exists
operation, such as $eq
property: P
name of property to calculate range for
value: LensResult<T, P, D>
value to use for range calculation.
optionalusingDotNotation: D
Returns [number, number]
[start, end] index array positions
calculateRangeStart
Internal method used for index maintenance and indexed searching. Calculates the beginning of an index range for a given value. For index maintenance (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.
Type parameters
- P: ValidSimpleLensField
- D: boolean
Parameters
property: ValidSimpleLensField
name of property which has binary index
value: LensResult<T, P, D>
value to find within index
optionaladaptive: boolean
if true, we will return insert position
optionalusingDotNotation: D
Returns number
chain
Chain method, used for beginning a series of chained find() and/or view() operations on a collection.
Returns ResultSet<T>
(this) resultset, or data array if any map or join-functions where called
checkAllIndexes
Perform checks to determine validity/consistency of all binary indices
Parameters
optionaloptions: Partial<ICheckCollectionIndexOptions>
optional configuration object
Returns any[]
array of index names where problems were found.
checkIndex
Perform checks to determine validity/consistency of a binary index
Parameters
property: keyof T
name of the binary-indexed property to check
optionaloptions: Partial<ICheckCollectionIndexOptions>
optional configuration object
optionalusingDotNotation: boolean
Returns boolean
whether the index was found to be valid (before optional correcting).
clear
Empties the collection.
Parameters
optionaloptions: Partial<IClearCollectionOptions>
configure clear behavior
Returns void
commitStage
(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 commit log
Parameters
stageName: string
name of stage
message: string
Returns void
configureOptions
Will allow reconfiguring certain collection options.
Parameters
options: IConfigureCollectionOptions
Returns void
count
Quickly determine number of documents in collection (or query)
Parameters
optionalquery: Partial<{ [ Key in string | number | symbol ]: DotNotationValue<T, Key> | Partial<{ $aeq: DotNotationValue<T, Key>; $between: DotNotationValue<T, Key> extends number ? [number, number] : never; $contains: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsAny: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsNone: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsString: DotNotationValue<T, Key> extends string ? string : never; $definedin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $dteq: DotNotationValue<T, Key> extends string | number | Date ? Date : never; $elemMatch: DotNotationValue<T, Key> extends ArrayLike<E> ? E extends object ? Partial<{ [Key in DotNotation<E>]: DotNotationValue<E, Key> | Partial<{ $size: DotNotationValue<E, Key> extends Set<any> | ArrayLike<...> ? number : never; ... 32 more ...; $exists: unknown; }>; }> : never : never; $eq: DotNotationValue<T, Key>; $exists: unknown; $finite: DotNotationValue<T, Key> extends number ? boolean : never; $gt: DotNotationValue<T, Key> extends number ? number : never; $gte: DotNotationValue<T, Key> extends number ? number : never; $in: DotNotationValue<T, Key>[]; $inSet: Set<DotNotationValue<T, Key>>; $jbetween: DotNotationValue<T, Key> extends number ? [number, number] : never; $jgt: DotNotationValue<T, Key> extends number ? number : never; $jgte: DotNotationValue<T, Key> extends number ? number : never; $jlt: DotNotationValue<T, Key> extends number ? number : never; $jlte: DotNotationValue<T, Key> extends number ? number : never; $keyin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $len: DotNotationValue<T, Key> extends ArrayLike<any> ? number : never; $lt: DotNotationValue<T, Key> extends number ? number : never; $lte: DotNotationValue<T, Key> extends number ? number : never; $ne: DotNotationValue<T, Key>; $nin: DotNotationValue<T, Key>[]; $nkeyin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $not: Partial<{ [Key in DotNotation<DotNotationValue<T, Key>>]: DotNotationValue<DotNotationValue<T, Key>, Key> | Partial<...>; }>; $regex: DotNotationValue<T, Key> extends string ? RegExp : never; $size: DotNotationValue<T, Key> extends Set<any> | ArrayLike<any> ? number : never; $type: Type; $undefinedin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $where: (x: DotNotationValue<T, Key>) => boolean }> }>
(optional) query object to count results of
Returns number
number of documents in the collection
createChange
Parameters
name: string
operation: CollectionOperation
newObject: T
optionaloldObject: T
Returns void
createInsertChange
Parameters
object: T
Returns void
createUpdateChange
Parameters
object: T
newObject: T
Returns void
dispatchEvent
Type parameters
- T: EventName<any, T>
Parameters
event: Event<EventDetail<T>>
Returns boolean
ensureAllIndexes
Ensure all binary indices
Parameters
optionalforce: boolean
whether to force rebuild of existing lazy binary indices
Returns void
ensureId
Rebuild idIndex
Returns void
ensureIdAsync
Rebuild idIndex async with callback - useful for background syncing with a remote server
Returns Promise<void>
ensureIndex
Ensure binary index on a certain field
Parameters
property: ValidSimpleLensField
name of property to create binary index on
optionalforce: boolean
(Optional) flag indicating whether to construct index immediately
Returns void
ensureUniqueIndex
Type parameters
Parameters
field: P
Returns UniqueIndex<T>
eqJoin
Join two collections on specified properties
Type parameters
- R: object
Parameters
joinData: Collection<R> | ResultSet<R> | R[]
array of documents to ‘join’ to this collection
leftJoinKey: keyof T | JoinKeyFunction<T>
rightJoinKey: JoinKeyFunction<R> | keyof R
Returns ResultSet<{ left: T; right: R }>
Result of the mapping operation
extract
Type parameters
- K: string | number | symbol
Parameters
field: K
Returns LensResult<T & ICollectionDocument, K, ValidDotNotation<K>>[]
extractNumerical
Type parameters
- K: string | number | symbol
Parameters
field: K
Returns number[]
find
Find method, api is similar to mongodb. for more complex queries use [chain()]chain or [where()]where.
Parameters
optionalquery: Partial<{ [ Key in string | number | symbol ]: DotNotationValue<T, Key> | Partial<{ $aeq: DotNotationValue<T, Key>; $between: DotNotationValue<T, Key> extends number ? [number, number] : never; $contains: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsAny: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsNone: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsString: DotNotationValue<T, Key> extends string ? string : never; $definedin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $dteq: DotNotationValue<T, Key> extends string | number | Date ? Date : never; $elemMatch: DotNotationValue<T, Key> extends ArrayLike<E> ? E extends object ? Partial<{ [Key in DotNotation<E>]: DotNotationValue<E, Key> | Partial<{ $size: DotNotationValue<E, Key> extends Set<any> | ArrayLike<...> ? number : never; ... 32 more ...; $exists: unknown; }>; }> : never : never; $eq: DotNotationValue<T, Key>; $exists: unknown; $finite: DotNotationValue<T, Key> extends number ? boolean : never; $gt: DotNotationValue<T, Key> extends number ? number : never; $gte: DotNotationValue<T, Key> extends number ? number : never; $in: DotNotationValue<T, Key>[]; $inSet: Set<DotNotationValue<T, Key>>; $jbetween: DotNotationValue<T, Key> extends number ? [number, number] : never; $jgt: DotNotationValue<T, Key> extends number ? number : never; $jgte: DotNotationValue<T, Key> extends number ? number : never; $jlt: DotNotationValue<T, Key> extends number ? number : never; $jlte: DotNotationValue<T, Key> extends number ? number : never; $keyin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $len: DotNotationValue<T, Key> extends ArrayLike<any> ? number : never; $lt: DotNotationValue<T, Key> extends number ? number : never; $lte: DotNotationValue<T, Key> extends number ? number : never; $ne: DotNotationValue<T, Key>; $nin: DotNotationValue<T, Key>[]; $nkeyin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $not: Partial<{ [Key in DotNotation<DotNotationValue<T, Key>>]: DotNotationValue<DotNotationValue<T, Key>, Key> | Partial<...>; }>; $regex: DotNotationValue<T, Key> extends string ? RegExp : never; $size: DotNotationValue<T, Key> extends Set<any> | ArrayLike<any> ? number : never; $type: Type; $undefinedin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $where: (x: DotNotationValue<T, Key>) => boolean }> }>
‘mongo-like’ query object
Returns (T & ICollectionDocument)[]
Array of matching documents
findAndRemove
Applies a ‘mongo-like’ find query object removes all documents which match that filter.
Parameters
filterObject: Partial<{ [ Key in string | number | symbol ]: DotNotationValue<T, Key> | Partial<{ $aeq: DotNotationValue<T, Key>; $between: DotNotationValue<T, Key> extends number ? [number, number] : never; $contains: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsAny: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsNone: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsString: DotNotationValue<T, Key> extends string ? string : never; $definedin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $dteq: DotNotationValue<T, Key> extends string | number | Date ? Date : never; $elemMatch: DotNotationValue<T, Key> extends ArrayLike<E> ? E extends object ? Partial<{ [Key in DotNotation<E>]: DotNotationValue<E, Key> | Partial<{ $size: DotNotationValue<E, Key> extends Set<any> | ArrayLike<...> ? number : never; ... 32 more ...; $exists: unknown; }>; }> : never : never; $eq: DotNotationValue<T, Key>; $exists: unknown; $finite: DotNotationValue<T, Key> extends number ? boolean : never; $gt: DotNotationValue<T, Key> extends number ? number : never; $gte: DotNotationValue<T, Key> extends number ? number : never; $in: DotNotationValue<T, Key>[]; $inSet: Set<DotNotationValue<T, Key>>; $jbetween: DotNotationValue<T, Key> extends number ? [number, number] : never; $jgt: DotNotationValue<T, Key> extends number ? number : never; $jgte: DotNotationValue<T, Key> extends number ? number : never; $jlt: DotNotationValue<T, Key> extends number ? number : never; $jlte: DotNotationValue<T, Key> extends number ? number : never; $keyin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $len: DotNotationValue<T, Key> extends ArrayLike<any> ? number : never; $lt: DotNotationValue<T, Key> extends number ? number : never; $lte: DotNotationValue<T, Key> extends number ? number : never; $ne: DotNotationValue<T, Key>; $nin: DotNotationValue<T, Key>[]; $nkeyin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $not: Partial<{ [Key in DotNotation<DotNotationValue<T, Key>>]: DotNotationValue<DotNotationValue<T, Key>, Key> | Partial<...>; }>; $regex: DotNotationValue<T, Key> extends string ? RegExp : never; $size: DotNotationValue<T, Key> extends Set<any> | ArrayLike<any> ? number : never; $type: Type; $undefinedin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $where: (x: DotNotationValue<T, Key>) => boolean }> }>
‘mongo-like’ query object
Returns ResultSet<T>
findAndUpdate
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.
Parameters
filterObject: Partial<{ [ Key in string | number | symbol ]: DotNotationValue<T, Key> | Partial<{ $aeq: DotNotationValue<T, Key>; $between: DotNotationValue<T, Key> extends number ? [number, number] : never; $contains: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsAny: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsNone: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsString: DotNotationValue<T, Key> extends string ? string : never; $definedin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $dteq: DotNotationValue<T, Key> extends string | number | Date ? Date : never; $elemMatch: DotNotationValue<T, Key> extends ArrayLike<E> ? E extends object ? Partial<{ [Key in DotNotation<E>]: DotNotationValue<E, Key> | Partial<{ $size: DotNotationValue<E, Key> extends Set<any> | ArrayLike<...> ? number : never; ... 32 more ...; $exists: unknown; }>; }> : never : never; $eq: DotNotationValue<T, Key>; $exists: unknown; $finite: DotNotationValue<T, Key> extends number ? boolean : never; $gt: DotNotationValue<T, Key> extends number ? number : never; $gte: DotNotationValue<T, Key> extends number ? number : never; $in: DotNotationValue<T, Key>[]; $inSet: Set<DotNotationValue<T, Key>>; $jbetween: DotNotationValue<T, Key> extends number ? [number, number] : never; $jgt: DotNotationValue<T, Key> extends number ? number : never; $jgte: DotNotationValue<T, Key> extends number ? number : never; $jlt: DotNotationValue<T, Key> extends number ? number : never; $jlte: DotNotationValue<T, Key> extends number ? number : never; $keyin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $len: DotNotationValue<T, Key> extends ArrayLike<any> ? number : never; $lt: DotNotationValue<T, Key> extends number ? number : never; $lte: DotNotationValue<T, Key> extends number ? number : never; $ne: DotNotationValue<T, Key>; $nin: DotNotationValue<T, Key>[]; $nkeyin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $not: Partial<{ [Key in DotNotation<DotNotationValue<T, Key>>]: DotNotationValue<DotNotationValue<T, Key>, Key> | Partial<...>; }>; $regex: DotNotationValue<T, Key> extends string ? RegExp : never; $size: DotNotationValue<T, Key> extends Set<any> | ArrayLike<any> ? number : never; $type: Type; $undefinedin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $where: (x: DotNotationValue<T, Key>) => boolean }> }> | FilterFunction<T>
‘mongo-like’ query object (or deprecated filterFunction mode)
updateFunction: (x: T & ICollectionDocument) => void | (T & ICollectionDocument)
update function to run against filtered documents
Returns void | ResultSet<T>
findObject
Type parameters
- P: object
Parameters
template: P
Returns T & ICollectionDocument
findObjects
Type parameters
- P: object
Parameters
template: P
Returns (T & ICollectionDocument)[]
findOne
Find one object by index property, by property equal to value
Parameters
query: Partial<Partial<{ [ Key in string | number | symbol ]: DotNotationValue<T, Key> | Partial<{ $aeq: DotNotationValue<T, Key>; $between: DotNotationValue<T, Key> extends number ? [number, number] : never; $contains: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsAny: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsNone: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsString: DotNotationValue<T, Key> extends string ? string : never; $definedin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $dteq: DotNotationValue<T, Key> extends string | number | Date ? Date : never; $elemMatch: DotNotationValue<T, Key> extends ArrayLike<E> ? E extends object ? Partial<{ [Key in DotNotation<E>]: DotNotationValue<E, Key> | Partial<{ $size: DotNotationValue<E, Key> extends Set<any> | ArrayLike<...> ? number : never; ... 32 more ...; $exists: unknown; }>; }> : never : never; $eq: DotNotationValue<T, Key>; $exists: unknown; $finite: DotNotationValue<T, Key> extends number ? boolean : never; $gt: DotNotationValue<T, Key> extends number ? number : never; $gte: DotNotationValue<T, Key> extends number ? number : never; $in: DotNotationValue<T, Key>[]; $inSet: Set<DotNotationValue<T, Key>>; $jbetween: DotNotationValue<T, Key> extends number ? [number, number] : never; $jgt: DotNotationValue<T, Key> extends number ? number : never; $jgte: DotNotationValue<T, Key> extends number ? number : never; $jlt: DotNotationValue<T, Key> extends number ? number : never; $jlte: DotNotationValue<T, Key> extends number ? number : never; $keyin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $len: DotNotationValue<T, Key> extends ArrayLike<any> ? number : never; $lt: DotNotationValue<T, Key> extends number ? number : never; $lte: DotNotationValue<T, Key> extends number ? number : never; $ne: DotNotationValue<T, Key>; $nin: DotNotationValue<T, Key>[]; $nkeyin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $not: Partial<{ [Key in DotNotation<DotNotationValue<T, Key>>]: DotNotationValue<DotNotationValue<T, Key>, Key> | Partial<...>; }>; $regex: DotNotationValue<T, Key> extends string ? RegExp : never; $size: DotNotationValue<T, Key> extends Set<any> | ArrayLike<any> ? number : never; $type: Type; $undefinedin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $where: (x: DotNotationValue<T, Key>) => boolean }> }>> = {}
query object used to perform search with
Returns T & ICollectionDocument
First matching document, or null if none
findOneUnIndexed
Find object by un-indexed field by property equal to value, simply iterates and returns the first element matching the query
Type parameters
- K: string | number | symbol
Parameters
property: K
value: T[K]
Returns T & ICollectionDocument
flushChanges
Returns void
get
Get by Id - faster than other methods because of the searching algorithm
Parameters
id: number
$loki id of document you want to retrieve
returnPosition: true
if ‘true’ we will return [object, position]
Returns [T & ICollectionDocument, number]
Object reference if document was found, null if not, or an array if ‘returnPosition’ was passed.
getBinaryIndexPosition
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.
Type parameters
- K: string | number | symbol
- D: boolean
Parameters
dataPosition: number
coll.data array index/position
binaryIndexName: K
index to search for dataPosition in
optionalusingDotNotation: D
Returns number
getBinaryIndexValues
Parameters
property: ValidSimpleLensField
Returns unknown[]
getChangeDelta
Compare changed object (which is a forced clone) with existing object and return the delta
Type parameters
- P
Parameters
newObject: P
optionaloldObject: P
Returns any
getChanges
Returns ICollectionChange<T>[]
getDynamicView
Look up dynamic view reference from within the collection
Parameters
name: string
name of dynamic view to retrieve reference of
Returns DynamicView<T>
A reference to the dynamic view with that name
getObjectDelta
Type parameters
- P
Parameters
oldObject: P
newObject: P
Returns P | Partial<T>
getStage
(Staging API) create a stage and/or retrieve it
Parameters
name: string
Returns Record<number, T & ICollectionDocument>
getTransform
Retrieves a named transform from the collection.
Parameters
name: string
name of the transform to lookup.
Returns TransformRequest<T, any, any>[]
getUniqueIndex
Returns a named unique index
Parameters
field: ValidSimpleLensField
indexed field name
optionalforce: boolean
if
true, will rebuild index; otherwise, function may return null
Returns any
insert
Adds object(s) to collection, ensure object(s) have meta properties, clone it if necessary, etc.
Parameters
documents: T
the document (or array of documents) to be inserted
optionaloverrideAdaptiveIndices: boolean
(optional) if
true, adaptive indices 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
Returns T & ICollectionDocument
document or documents inserted
insertMeta
Parameters
object: T
Returns void
insertMetaWithChange
Parameters
object: T
Returns void
insertOne
Adds a single object, ensures it has meta properties, clone it if necessary, etc.
Parameters
document: T
the document to be inserted
optionalbulkInsert: boolean
quiet pre-insert and insert event emits
Returns any
document or ‘undefined’ if there was a problem inserting it
mapReduce
Map Reduce operation
Type parameters
- P
- U
Parameters
mapFunction: (x: T & ICollectionDocument) => P
function to use as map function
reduceFunction: (x: P[]) => U
function to use as reduce function
Returns U
The result of your mapReduce operation
max
Type parameters
- K: string | number | symbol
Parameters
field: K
Returns any
maxRecord
Type parameters
- K: string | number | symbol
Parameters
field: K
Returns { index: number; value: number }
index: number
value: number
mean
Calculates the average numerical value of a property
Type parameters
- K: string | number | symbol
Parameters
field: K
name of property in docs to average
Returns number
average of property in all docs in the collection
median
Type parameters
- K: string | number | symbol
Parameters
field: K
Returns number
min
Type parameters
- K: string | number | symbol
Parameters
field: K
Returns any
minRecord
Type parameters
- K: string | number | symbol
Parameters
field: K
Returns { index: number; value: number }
index: number
value: number
mode
Type parameters
- K: string | number | symbol
Parameters
field: K
Returns number
observerCallback
Parameters
data: T & ICollectionDocument
Returns T & ICollectionDocument
prepareFullDocIndex
create a row filter that covers all documents in the collection
Returns number[]
remove
Remove a document from the collection
Parameters
document: number | (T & ICollectionDocument) | (number | (T & ICollectionDocument))[]
document to remove from collection
Returns T & ICollectionDocument
removeBatchByPositions
Internal method to remove a batch of documents from the collection.
Parameters
positions: number[]
data/idIndex positions to remove
Returns any
removeDataOnly
Returns void
removeDynamicView
Remove a dynamic view from the collection
Parameters
name: string
name of dynamic view to remove
Returns void
removeEventListener
Type parameters
- T: EventName<any, T>
Parameters
type: EventName<T>
callback: Listener<T>
optionaloptions: boolean | EventListenerOptions
Returns void
removeTransform
Removes a named collection transform from the collection
Parameters
name: string
name of collection transform to remove
Returns void
removeWhere
Remove all documents matching supplied filter function. For ‘mongo-like’ querying you should migrate to [findAndRemove()]findAndRemove.
Parameters
query: Partial<{ [ Key in string | number | symbol ]: DotNotationValue<T, Key> | Partial<{ $aeq: DotNotationValue<T, Key>; $between: DotNotationValue<T, Key> extends number ? [number, number] : never; $contains: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsAny: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsNone: DotNotationValue<T, Key> extends ArrayLike<E> ? E : never; $containsString: DotNotationValue<T, Key> extends string ? string : never; $definedin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $dteq: DotNotationValue<T, Key> extends string | number | Date ? Date : never; $elemMatch: DotNotationValue<T, Key> extends ArrayLike<E> ? E extends object ? Partial<{ [Key in DotNotation<E>]: DotNotationValue<E, Key> | Partial<{ $size: DotNotationValue<E, Key> extends Set<any> | ArrayLike<...> ? number : never; ... 32 more ...; $exists: unknown; }>; }> : never : never; $eq: DotNotationValue<T, Key>; $exists: unknown; $finite: DotNotationValue<T, Key> extends number ? boolean : never; $gt: DotNotationValue<T, Key> extends number ? number : never; $gte: DotNotationValue<T, Key> extends number ? number : never; $in: DotNotationValue<T, Key>[]; $inSet: Set<DotNotationValue<T, Key>>; $jbetween: DotNotationValue<T, Key> extends number ? [number, number] : never; $jgt: DotNotationValue<T, Key> extends number ? number : never; $jgte: DotNotationValue<T, Key> extends number ? number : never; $jlt: DotNotationValue<T, Key> extends number ? number : never; $jlte: DotNotationValue<T, Key> extends number ? number : never; $keyin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $len: DotNotationValue<T, Key> extends ArrayLike<any> ? number : never; $lt: DotNotationValue<T, Key> extends number ? number : never; $lte: DotNotationValue<T, Key> extends number ? number : never; $ne: DotNotationValue<T, Key>; $nin: DotNotationValue<T, Key>[]; $nkeyin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $not: Partial<{ [Key in DotNotation<DotNotationValue<T, Key>>]: DotNotationValue<DotNotationValue<T, Key>, Key> | Partial<...>; }>; $regex: DotNotationValue<T, Key> extends string ? RegExp : never; $size: DotNotationValue<T, Key> extends Set<any> | ArrayLike<any> ? number : never; $type: Type; $undefinedin: DotNotationValue<T, Key> extends object ? keyof DotNotationValue<T, Key> : never; $where: (x: DotNotationValue<T, Key>) => boolean }> }> | FilterFunction<T>
query object to filter on
Returns void
rollback
roll back the transaction
Returns void
setChangesApi
Parameters
enabled: boolean
Returns void
setTTL
Updates or applies collection TTL settings.
Parameters
age: number
age (in ms) to expire document from collection
interval: number
time (in ms) to clear collection of aged documents.
Returns void
setTransform
Updates a named collection transform to the collection
Parameters
name: string
name to associate with transform
transform: TransformRequest<T, T, T>[]
a transformation object to save into collection
Returns void
stage
(Staging API) create a copy of an object and insert it into a stage
Parameters
stageName: string
document: T & ICollectionDocument
Returns any
standardDeviation
Type parameters
- K: string | number | symbol
Parameters
field: K
Returns number
ttlDaemonFuncGen
Returns () => void
Returns void
update
Updates an object and notifies collection that the document has changed.
Parameters
document: (T & ICollectionDocument) | (T & ICollectionDocument)[]
document to update within the collection
Returns any
updateMeta
Parameters
object: T
Returns T
updateMetaWithChange
Parameters
object: T
oldObject: T
Returns T
updateWhere
Applies a filter function and passes all results to an update function.
Parameters
filterFunction: FilterFunction<T>
filter function whose results will execute update
updateFunction: (x: T & ICollectionDocument) => void | (T & ICollectionDocument)
update function to run against filtered documents
Returns void
where
Query the collection by supplying a javascript filter function.
Parameters
filter: FilterFunction<T>
filter function to run against all collection docs
Returns (T & ICollectionDocument)[]
all documents which pass your filter function
Collection class that handles documents of same type
collection name
(optional) array of property names to be indicted OR a configuration object
addCollection for normal creation of collections