-
Notifications
You must be signed in to change notification settings - Fork 16
K.9 Order and Limit Data
Cloud Firestore provides powerful query functionality for specifying which documents you want to retrieve from a collection. These queries can also be used with either read() or addSnapshotListener(), as described in Get Data.
Cloud Firestore also lets you specify the sort order for your data and specify a limit to how many documents you want to retrieve using orderBy() and limit(). For example, you could query for the first 3 cities alphabetically with:
citiesRef.orderBy("name").limit(3);
You could also sort in descending order to get the last 3 cities:
citiesRef.orderBy("name", Query.DESCENDING).limit(3);
You can also order by multiple fields. For example, if you wanted to order by state, and within each state order by population in descending order:
citiesRef.orderBy("state").orderBy("population", Query.DESCENDING);
You can combine where() filters with orderBy() and limit(). In the following example, the queries define a population threshold, sort by population in ascending order, and return only the first few results that exceed the threshold:
citiesRef.whereGreaterThan("population", 100000).orderBy("population").limit(2);
To learn more about valid and invalid limit/order queries, read here.
Enjoy building Air apps – With ♥ from MyFlashLabs Team
Introduction to Firebase ANEs collection for Adobe Air apps
Get Started with Firebase Core in AIR
- Prerequisites
- Add Firebase to your app
- Add the Firebase SDK
- Init Firebase Core
- Available ANEs
- Managing Firebase iid
Get Started with Authentication
- Add Authentication
- Init Authentication
- Manage Users
- Phone Number
- Custom Auth
- Anonymous Auth
- State in Email Actions
- Email Link Authentication
Get Started with FCM + OneSignal
- Add FCM ANE
- Init FCM ANE
- Send Your 1st Message
- Send Msg to Topics
- Understanding FCM Messages
- init OneSignal
- Add Firestore
- Init Firestore
- Add Data
- Transactions & Batches
- Delete Data
- Manage the Console
- Get Data
- Get Realtime Updates
- Simple and Compound
- Order and Limit Data
- Paginate Data
- Manage Indexes
- Secure Data
- Offline Data
- Where to Go From Here
Get Started with Realtime Database
- Add Realtime Database
- Init Realtime Database
- Structure Your Database
- Save Data
- Retrieve Data
- Enable Offline Capabilities
Get Started with Remote Config
- Add Storage ANE
- Init Storage ANE
- Upload Files to Storage
- Download Files to Air
- Use File Metadata
- Delete Files