Firebase Query can be used to order a collection of data based on some attributes as well as restricted to the large list of items (for like chat data) down to a number suitable for synchronizing to the client.
Just as with a Reference, you can receive data from a Query by using the on() method. You will only receive events and DataSnapshots for the subset of the data that matches your query.