The Firebase JS SDK is now in BETA!
This EAP site is no longer maintained. See the official Firebase Documentation site for the latest documentation and information about the Firebase JS SDK.

Home > @firebase/database > limitToLast

limitToLast() function

Creates a new QueryConstraint that is limited to return only the last specified number of children.

The limitToLast() method is used to set a maximum number of children to be synced for a given callback. If we set a limit of 100, we will initially only receive up to 100 child_added events. If we have fewer than 100 messages stored in our Database, a child_added event will fire for each message. However, if we have over 100 messages, we will only receive a child_added event for the last 100 ordered messages. As items change, we will receive child_removed events for each item that drops out of the active list so that the total number stays at 100.

You can read more about limitToLast() in Filtering data.

Signature:

export declare function limitToLast(limit: number): QueryConstraint;

Parameters

Parameter Type Description
limit number The maximum number of nodes to include in this query.

Returns:

QueryConstraint