Reputation: 1484
I have a chat system, and i want to show the most recent chat message outside for the user to see before joining the chat.
Is there a Firebase way to accomplish this without actually pulling the whole conversation and getting the last one?
Upvotes: 0
Views: 1568
Reputation: 80914
You can use limitToLast()
to get the last item in the database:
/// Create a query with limit and anchor it to the end of the window.
Query limitToLast(int limit) {
assert(!_parameters.containsKey('limitToLast'));
return _copyWithParameters(<String, dynamic>{'limitToLast': limit});
}
Upvotes: 2