Firestore whereEqualTo, orderBy and limit(1) not working
This query will not work unless you create an index for it. This can be done, by creating it manually in your Firebase Console or if you are using Android Studio, you'll find in your logcat a message that sounds like this:
FAILED_PRECONDITION: The query requires an index. You can create it here: ...
You can simply click on that link or copy and paste the URL into a web browser and your index will be created automatically.
Firestore Query whereEqualTo along with whereGreaterThan not working
You cannot put multiple conditions with different fields in a query without a composite index.
You can find more info in the official documentation:
https://firebase.google.com/docs/firestore/query-data/index-overview
https://firebase.google.com/docs/firestore/query-data/indexing
BTW, firebase creates a link to create these indexes, usually, it can be found in console (logcat in android case)
Perform whereEqualTo with orderBy in firestore
You might need an index on "Type". An error message with an URL should be printed in your logcat as well. If you can find that, just click on that URL. Otherwise, try to create one manually..
https://firebase.google.com/docs/firestore/query-data/indexing
How to use whereEqualTo() and orderBy() in a Firebase Firestore query?
The document field for the filter is called "fulfilled", but you are using "isFulfilled" to filter it. That won't work at all. You must use the same name of the actual field.
database
.collection("Orders")
.whereEqualTo("Donor", email)
.whereEqualTo("fulfilled", false)
.orderBy("timestamp", Query.Direction.DESCENDING).get()
Error is coming while get query in Android Studio Firestore
The error message is quite explicit about the error. You are using both "whereGreaterThan()" and "whereLessThan()" on the "postDate" field, but you aren't first ordering the results based on that field, hence that error. Please remember, that the order of the method calls in Firestore is very important. To solve this, please change your query to:
query = database.collection("CustomerViews/Data/Post")
.orderBy("postDate", Query.Direction.DESCENDING)
.whereGreaterThanOrEqualTo("postDate", startDate)
.whereLessThanOrEqualTo("postDate", endDate)
.orderBy("postViews", Query.Direction.DESCENDING)
And right after that, simply create the corresponding index. That's it.
Edit:
According to your first comment:
By using your code data is coming but "postViews" descending is not happening. Only postDate descending is coming.
Yes, the results will be returned descending according to "postDate". And if two or more elements will have the same "postDate", then only those results will be after that ordered descending according to "postViews". This is how Firestore works.
According to your second comment:
I want the "postViews" in descending order in given date ranges.
Cloud Firestore queries can only sort or filter range on a single field. What you are trying to achieve it's not possible, since you are trying to filter on "postDate" and then order on "postViews".
In the official documentation, there is an example on how not to do it:
Range filter and first orderBy on different fields
citiesRef.whereGreaterThan("population", 100000).orderBy("country"); //Invalid
According to your last comment:
I got the solution for my problem. I have added the below line before attaching the ArrayList to an adapter.
postArrayList.sortByDescending { it.PostViews }
Indeed it will work if you download all documents on the client and to the filtering there, but it will cost you one document read for each document you download.
Why firestore multiple whereEqualTo are not working
You're querying over terminal
but the actual key in your db is terminalId
Android firebase firestore how to initialize recyclerview
I'm not sure what is the problem. If the list is duplicated and you want the new one to be replaced for the old one just empty your current list (I guess you use userArrayList to show items in the recycler view) and add the new content.
What I mean is to re-initialize the list before adding new content if you don't want to duplicate content.
Related Topics
Firebase Ui Authentication With Google Fails With Message (Code:10 Message:10)
Virtual Memory Usage from Java Under Linux, Too Much Memory Used
Java Inner Class and Static Nested Class
How to Deal With "Java.Lang.Outofmemoryerror: Java Heap Space" Error
Design Patterns Web Based Applications
Explanation of Classcastexception in Java
Why Does Gson Fromjson Throw a Jsonsyntaxexception: Expected Begin_Object But Was Begin_Array
How to "Scan" a Website (Or Page) For Info, and Bring It into My Program
How to Get the Download Url from Firebase Storage
How to Request Location Permission At Runtime
Running Jmap Getting Unable to Open Socket File
How to Add Jtable in Jpanel With Null Layout
How to Convert My Java Program to an .Exe File
Including All the Jars in a Directory Within the Java Classpath