An index is a specialized persistent key-value storage and has a referenced . The index has a list of records which hold the data stored in the index. The records in an index are automatically populated whenever records in the referenced object store are inserted, updated or deleted. There can be several referencing the same object store, in which changes to the object store cause all such indexes to get updated.

    The values in the index’s are always values of keys in the index’s object store. The keys are derived from the referenced object store’s values using a key path. If a given with key X in the object store referenced by the index has the value A, and evaluating the index’s on A yields the result Y, then the index will contain a record with key Y and value X.

    For example, if an index’s object store contains a record with the key and the value { name: "Alice", title: "CEO" }, and the index’s key path is ““ then the index would contain a record with the key “Alice“ and the value .

    In the preceding example, the record in the index with key “Alice“ and value would have a referenced value of { name: "Alice", title: "CEO" }.

    Each record in an index references one and only one record in the index’s object store. However there can be multiple records in an index which reference the same record in the object store. And there can also be no records in an index which reference a given record in an object store.

    The records in an index are always sorted according to the ‘s key. However unlike object stores, a given index can contain multiple records with the same key. Such records are additionally sorted according to the index‘s ‘s value (meaning the key of the record in the referenced object store).

    An has a unique flag. When true, the index enforces that no two records in the index has the same key. If a in the index’s referenced object store is attempted to be inserted or modified such that evaluating the index’s key path on the records new value yields a result which already exists in the index, then the attempted modification to the object store fails.

    An index has a multiEntry flag. This flag affects how the index behaves when the result of evaluating the index’s yields an array key. If its is false, then a single record whose is an array key is added to the index. If its is true, then one record is added to the index for each of the .

    2.6.1. Index handle

    Script does not interact with indexes directly. Instead, within a , script has indirect access via an index handle.

    An index handle has a name, which is initialized to the of the associated index when the is created. The name will remain constant except when an upgrade transaction is running.