This question already has answers here:
Firebase Android - startAt() and endAt() not working correctly?
(2 answers)
Closed 3 years ago.
I have objects named "trips" saved in the firebase database, which can uniquely identify using seasonCode and TripCode combination.
Now I want to retrieve all the trips which include a particular seasonCode (ex: trips with seasonCode="SeasonCose1"). but need to extract data set chunk wise. (let's say 10 trips at a time)
FirebaseDatabase.getInstance(firebaseApp).getReference("resources").child("trips").orderByChild("seasonCode").equalTo("seasonCode1").limitToFirst(10)
I figured this query returns first 10 trips wich seasonCode="SeasonCode1". if I have last retrieved "Trip" object, how can I retrieve the next 10 trips with seasonCode="seasonCode1"?
Finally found a solution. I can get that through wildcard queries.
Firebase Android - startAt() and endAt() not working correctly?
Related
This question already has answers here:
Query based on multiple where clauses in Firebase
(8 answers)
Firebase multiple WHERE clause in query [duplicate]
(2 answers)
Closed 4 months ago.
First of all, I am coding in Kotlin.
I'd like to arrange the posts stored in the Realtime Database for a certain period of time based on the number of likes and display them in the RecyclerView.
my database structure
"posts": {
"key": {
"uid": "NHYVkW...",
"title" : "Title",
"time": "1666852764028",
"like" : 2
}
I've read about methods orderByChild(), startAt(), and endAt(), but I don't know how to use them in combination.
The examples I've seen set startAt() and endAt() for the key that enters orderByChild().
But I want the sort to be based on like and the start and end points based on time.
Any examples I can refer to?
Please help.
This question already has answers here:
How to sort Firebase records by two fields (Android) [duplicate]
(1 answer)
Query based on multiple where clauses in Firebase
(8 answers)
Closed 8 months ago.
I am trying to get data of "fromuser" equals to "moeez" and "status" equals to "pending" in firebase
using query
Query query1 = databaseReference.child("fromuser").equalTo(name).orderByChild("status").equalTo(status_value);
gives error java.lang.IllegalArgumentException: You can't combine multiple orderBy calls!
Now how can i retrieve both values at same time to display sorted data??
This question already has answers here:
Android Firebase multiple sort
(1 answer)
How to sort Firebase records by two fields (Android) [duplicate]
(1 answer)
Filter and sort on multiple values with Firebase
(1 answer)
Closed 3 years ago.
I am using Firebase Recycler Adapter on the Real Time Data Base (RTDB). Unfortunately, the query feature for the RTDB is quite limited and is causing me some problems. Here is the problem I am trying to solve:
Imagine I have an object model consisting of the name and the national origin of a person. I can query all the people with a particular national origin as shown below:
Query query = FirebaseDatabase.getInstance().getReference().child("People").orderByChild("nationalOrigin").equalTo("USA");
FirebaseRecyclerOptions<People> options = new FirebaseRecyclerOptions.Builder<People>()
.setQuery(query, People.class)
.build();
This correctly query all the people with national origin being "USA". However, what if I also want to sort the data alphabetically based on the name of the person before populating the recycle view. What is the best way of dong this?
Thanks in advance.
This question already has answers here:
Query based on multiple where clauses in Firebase
(8 answers)
Closed 5 years ago.
Query q = FirebaseDatabase.getInstance().getReference().child("Chats").orderByChild("senderkey")
.equalTo(FirebaseAuth.getInstance().getCurrentUser().getUid());
In the above code I'm querying using sender = x , what if i want to make this statement senderkey = x and receiverkey = y.
In short, how to use AND in firebase ?
because:
I’m displaying the data by querying by senderkey but I don’t want to display the duplicated data again, if the senderkey is repeated i want it to be displayed once
I don't think this is possible. You can't query on multiple children. If you know you want the last message with a specific sender id you can use the limitToLast() function which will eliminate the duplicate concern.
More info on Firebase Database Queries here: https://firebase.google.com/docs/database/admin/retrieve-data
These type of queries are not allowed in firebase realtime database You can use firestore for multiple where queries by the way.
If you want to stick with firebase realtime database then you should work on your data model and create combine key to search and perform AND operation.
For example to perform AND operation you need to create a key
"name_createdAt" = "chickungunya_moka"
and then do query for
orderByChild("name_reportedAt").equalsTo(name+"_"+reportedAt);
This question already has answers here:
Firebase android : make username unique
(4 answers)
Closed 5 years ago.
The problem I can't seem to find a straight answer to is how can I do a query on this list in the Firebase database by some field (a username in my case) to find the associated key for that user given that username is guaranteed to be a unique value.
I've read through the documentation on queries, but it looks like all of them need a key in some shape or form is that really the case? And if it is how is this normally avoided?
Thanks a million below is how my DB is designed.
Right now, in my database there is a list of user objects:
Database
-users
-{SomeUniqueKey}
-data: "some data"
-username: "user1"
-usernameThisUserIsFollowing: "user2"
+{SomeOtherUniqueKey}
You may use equalTo.
Reference: https://firebase.google.com/docs/database/