Query interface

AQuery sorts and filters the data at a Database location so only a subset of the child data is included. This can be used to order a collection of data by some attribute (for example, height of dinosaurs) as well as to restrict a large list of items (for example, chat messages) down to a number suitable for synchronizing to the client. Queries are created by chaining together one or more of the filter methods defined here.

Just as with aDatabaseReference, you can receive data from aQuery by using theon*() methods. You will only receive events andDataSnapshots for the subset of the data that matches your query.

Seehttps://firebase.google.com/docs/database/web/lists-of-data#sorting_and_filtering_data for more information.

Signature:

exportdeclareinterfaceQuery

Properties

PropertyTypeDescription
refDatabaseReferenceTheDatabaseReference for theQuery's location.

Methods

MethodDescription
isEqual(other)Returns whether or not the current and provided queries represent the same location, have the same query parameters, and are from the same instance ofFirebaseApp.TwoDatabaseReference objects are equivalent if they represent the same location and are from the same instance ofFirebaseApp.TwoQuery objects are equivalent if they represent the same location, have the same query parameters, and are from the same instance ofFirebaseApp. Equivalent queries share the same sort order, limits, and starting and ending points.
toJSON()Returns a JSON-serializable representation of this object.
toString()Gets the absolute URL for this location.ThetoString() method returns a URL that is ready to be put into a browser, curl command, or arefFromURL() call. Since all of those expect the URL to be url-encoded,toString() returns an encoded URL.Append '.json' to the returned URL when typed into a browser to download JSON-formatted data. If the location is secured (that is, not publicly readable), you will get a permission-denied error.

Query.ref

TheDatabaseReference for theQuery's location.

Signature:

readonlyref:DatabaseReference;

Query.isEqual()

Returns whether or not the current and provided queries represent the same location, have the same query parameters, and are from the same instance ofFirebaseApp.

TwoDatabaseReference objects are equivalent if they represent the same location and are from the same instance ofFirebaseApp.

TwoQuery objects are equivalent if they represent the same location, have the same query parameters, and are from the same instance ofFirebaseApp. Equivalent queries share the same sort order, limits, and starting and ending points.

Signature:

isEqual(other:Query|null):boolean;

Parameters

ParameterTypeDescription
otherQuery | nullThe query to compare against.

Returns:

boolean

Whether or not the current and provided queries are equivalent.

Query.toJSON()

Returns a JSON-serializable representation of this object.

Signature:

toJSON():string;

Returns:

string

A JSON-serializable representation of this object.

Query.toString()

Gets the absolute URL for this location.

ThetoString() method returns a URL that is ready to be put into a browser, curl command, or arefFromURL() call. Since all of those expect the URL to be url-encoded,toString() returns an encoded URL.

Append '.json' to the returned URL when typed into a browser to download JSON-formatted data. If the location is secured (that is, not publicly readable), you will get a permission-denied error.

Signature:

toString():string;

Returns:

string

The absolute URL for this location.

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2024-01-19 UTC.