Skip to content

Collection.keys()

David Fahlander edited this page May 13, 2014 · 12 revisions

Syntax

collection.keys(callback)

Parameters

callback: Function function (keysArray) { } optional

Callback Parameters

keysArray: Array Array of keys

Return Value

Promise

Remarks

Given callback will recieve an array containing all keys of the index being indexed in the collection. Can only be used on indexes and not on primary keys.

If callback is omitted and operation succeeds, returned Promise will resolve with the result of the operation, calling any Promise.then() callback.

If callback is specified and operation succeeds, given callback will be called and the returned Promise will resolve with the return value of given callback.

If operation fails, returned promise will reject, calling any Promise.catch() callback.

Sample

// List all the first name of all my friends:
db.friends.orderBy('firstName').keys(function (firstNames) {
    alert ("My friends are: " + firstNames.join(','));
});

// List all shoeSizes that my friends have (duplicates removed):
db.friends.orderBy('shoeSize').uniqueKeys(function (shoeSizes) {
    alert ("My friends have the following shoe sizes: " + shoeSizes.join(','));
});
Clone this wiki locally