FirebaseFirestoreException: FAILED_PRECONDITION [duplicate] - android

This question already has an answer here:
Unexpected Behavior When Query by .whereArrayContains()
(1 answer)
Closed 4 years ago.
To get the data from the firestore collection for instance update I tried the below query.
docRef.whereArrayContains().orderBy().limit()
com.google.firebase.firestore.FirebaseFirestoreException: FAILED_PRECONDITION: The query requires an index. You can create it here:

If you attempt a compound query with a range clause that doesn't map to an existing index, you receive an error. The error message includes a direct link to create the missing index in the Firebase console.
Manage indexes in Cloud Firestore
When you get the error check LogCat for the link

Related

use two ordebychild() functions in firebase [duplicate]

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??

Firebase realtime Database query by child and paging result [duplicate]

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?

How to filter collections in Firebase Firestore? [duplicate]

This question already has answers here:
Google Firestore - How to get several documents by multiple ids in one round-trip?
(17 answers)
Closed 4 years ago.
I have below FireStore data
And I have a list specialUsers which is defined as
val specialUsers = arrayOf("stark#gmail.com", "lannester#gmail.com")
So I want to get collections which are in the specialUsers, something like
collection("users").whereIn(specialUsers)
But, couldn't find any documentation related to this. How can I perform above intention in Firestore?
As he says here in 6:19
There is still no way for the database to automatically grab specific user name and profile for each review as I requesting them. I would need to make separate database request for every single review I get to fetch this information and that's bad. so If we wont to automatically include information about who rote a particular review we will need to copy sample of the user profile to the particular review and this is the way (to brake data Normalization) specifically in could FireStore.

Querying with two child in Firebase [duplicate]

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);

WHERE equivalent for Firebase Realtime Database in Android [duplicate]

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/

Categories

Resources