Tarantool CE/EE Documentation portal logo
Support
Updated at July 17, 2026   02:08 PM

index_object:count()

index_object method count([key], [iterator])

Iterate over an index, counting the number of tuples which match the key-value.

Parameters:

  • index_object (index_object) — an object reference.

  • key (scalar/table) — values to be matched against the index key

  • iterator — comparison method

Returns

the number of matching tuples.

Return type

number

Example:

Below are few examples of using count. To try out these examples, you need to bootstrap a Tarantool database as described in Using data operations.

-- Insert test data --box.space.bands:insert { 1, 'Roxette', 1986 }box.space.bands:insert { 2, 'Scorpions', 1965 }box.space.bands:insert { 3, 'Ace of Base', 1987 }box.space.bands:insert { 4, 'The Beatles', 1960 }box.space.bands:insert { 5, 'Pink Floyd', 1965 }box.space.bands:insert { 6, 'The Rolling Stones', 1962 }box.space.bands:insert { 7, 'The Doors', 1965 }box.space.bands:insert { 8, 'Nirvana', 1987 }box.space.bands:insert { 9, 'Led Zeppelin', 1968 }box.space.bands:insert { 10, 'Queen', 1970 }-- Count the number of tuples that match the full key valuecount = box.space.bands.index.year:count(1965)--[[---- 3...--]]-- Count the number of tuples that match the partial key valuecount_partial = box.space.bands.index.year_band:count(1965)--[[---- 3...--]]