Skip to content
develephant edited this page Feb 4, 2016 · 1 revision

These methods require a cursor object. See Collections.

Methods:

Advancing

:next

Returns the next item and advances the cursor.

Parameters

None

Returns

Current index, and cursor item

local index, item = cursor:next()

:limit

Limits the number of cursor results.

Parameters

Name Description Default Required
amount The limit amount none No

Returns

Nothing

cursor:limit( amount )

:sort

Sorts cursor by given field and size.

Parameters

Name Description Default Required
field The field and direction to sort on none Yes
size Size of temp array to sort with 10000 No

Field and Direction

Provide a table for the field parameter.

Flag Sort Order
<field>=1 Ascending sort
<field>=-1 Descending sort
-- Sort on username ascending
{ username = 1 }
-- Sort on age descending
{ age = -1 }

Returns

A sorted table array.

local results = cursor:sort( field, size )

Looping

:pairs

A wrapper around cursor:next() that works in a generic for loop.

Parameters

None

Returns

Iterator function

for index, item in cursor:pairs() do
  print( index, item )
end
Clone this wiki locally