Indexes on field names, with atomic operations and which can optionally enforce a unique constraint or allow indexed fields to be undefined
**Kind**: global class * [Index](#Index) * [new Index(options)](#new_Index_new) * [.fieldName](#Index+fieldName) :string
* [.unique](#Index+unique) : boolean
* [.sparse](#Index+sparse) : boolean
* [.treeOptions](#Index+treeOptions) : Object
* [.tree](#Index+tree) : AVLTree
* [.reset([newData])](#Index+reset)
* [.insert(doc)](#Index+insert)
* [.remove(doc)](#Index+remove)
* [.update(oldDoc, [newDoc])](#Index+update)
* [.revertUpdate(oldDoc, [newDoc])](#Index+revertUpdate)
* [.getMatching(value)](#Index+getMatching) ⇒ [Array.<document>
](#document)
* [.getBetweenBounds(query)](#Index+getBetweenBounds) ⇒ [Array.<document>
](#document)
* [.getAll()](#Index+getAll) ⇒ [Array.<document>
](#document)
### new Index(options)
Create a new index All methods on an index guarantee that either the whole operation was successful and the index changed or the operation was unsuccessful and an error is thrown while the index is unchanged
**Params** - optionsobject
- .fieldName string
- On which field should the index apply (can use dot notation to index on sub fields)
- [.unique]boolean
= false
- Enforces a unique constraint
- [.sparse]boolean
= false
- Allows a sparse index (we can have documents for which fieldName is undefined
)
string
On which field the index applies to (may use dot notation to index on sub fields).
**Kind**: instance property of [Index
](#Index)
### index.unique : boolean
Defines if the index enforces a unique constraint for this index.
**Kind**: instance property of [Index
](#Index)
### index.sparse : boolean
Defines if we can have documents for which fieldName is undefined
Index
](#Index)
### index.treeOptions : Object
Options object given to the underlying BinarySearchTree.
**Kind**: instance property of [Index
](#Index)
### index.tree : AVLTree
Underlying BinarySearchTree for this index. Uses an AVLTree for optimization.
**Kind**: instance property of [Index
](#Index)
### index.reset([newData])
Reset an index
**Kind**: instance method of [Index
](#Index)
**Params**
- [newData] [document
](#document) | [?Array.<document>
](#document) - Data to initialize the index with. If an error is thrown during insertion, the index is not modified.
### index.insert(doc)Insert a new document in the index If an array is passed, we insert all its elements (if one insertion fails the index is not modified) O(log(n))
**Kind**: instance method of [Index
](#Index)
**Params**
- doc [document
](#document) | [Array.<document>
](#document) - The document, or array of documents, to insert.
### index.remove(doc)Removes a document from the index. If an array is passed, we remove all its elements The remove operation is safe with regards to the 'unique' constraint O(log(n))
**Kind**: instance method of [Index
](#Index)
**Params**
- doc [Array.<document>
](#document) | [document
](#document) - The document, or Array of documents, to remove.
### index.update(oldDoc, [newDoc])Update a document in the index If a constraint is violated, changes are rolled back and an error thrown Naive implementation, still in O(log(n))
**Kind**: instance method of [Index
](#Index)
**Params**
- oldDoc [document
](#document) | Array.<{oldDoc: document, newDoc: document}>
- Document to update, or an Array
of
{oldDoc, newDoc}
pairs.
document
](#document) - Document to replace the oldDoc with. If the first argument is an Array
of
{oldDoc, newDoc}
pairs, this second argument is ignored.
Revert an update
**Kind**: instance method of [Index
](#Index)
**Params**
- oldDoc [document
](#document) | Array.<{oldDoc: document, newDoc: document}>
- Document to revert to, or an Array
of {oldDoc, newDoc}
pairs.
document
](#document) - Document to revert from. If the first argument is an Array of {oldDoc, newDoc}, this second argument is ignored.
### index.getMatching(value) ⇒ [Array.<document>
](#document)
Get all documents in index whose key match value (if it is a Thing) or one of the elements of value (if it is an array of Things)
**Kind**: instance method of [Index
](#Index)
**Params**
- value Array.<\*>
| \*
- Value to match the key against
### index.getBetweenBounds(query) ⇒ [Array.<document>
](#document)
Get all documents in index whose key is between bounds are they are defined by query Documents are sorted by key
**Kind**: instance method of [Index
](#Index)
**Params**
- query object
- An object with at least one matcher among $gt, $gte, $lt, $lte.
- [.$gt]\*
- Greater than matcher.
- [.$gte]\*
- Greater than or equal matcher.
- [.$lt]\*
- Lower than matcher.
- [.$lte]\*
- Lower than or equal matcher.
### index.getAll() ⇒ [Array.<document>
](#document)
Get all elements in the index
**Kind**: instance method of [Index
](#Index)