Skip to content

Collection.count()

David Fahlander edited this page May 8, 2014 · 15 revisions

Syntax

collection.count(callback)

Parameters

callback: Function function (count) { } optional

Callback Parameters

count: Number Number of items in the collection

Return Value

Promise

Remarks

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.

Performance Notes

If executed on simple queries, the native IDB count() method will be called (fast execution). If advanced queries are used, the implementation have to execute a query to iterate all items and count them manually.

Examples where count() will be fast

  • db.[table].count()
  • db.[table].where(index).equals(value).count()
  • db.[table].where(index).above(value).count()
  • db.[table].where(index).below(value).count()
  • db.[table].where(index).between(value).count()
  • db.[table].where(index).startsWith(value).count()

Examples where count() will have to count manually:

  • db.[table].where(index).equalsIgnoreCase(value).count()
  • db.[table].where(index).startsWithIgnoreCase(value).count()
  • db.[table].where(index).anyOf(valueArray).count()
  • db.[table].where(index).above(value).and(filterFunction).count()
Clone this wiki locally