I am having issues with the code below, this statement is not returning sorted docs according to the sellingPrice.
databaseReference
.collection("products")
.where("tags", arrayContains: tag)
.where("totalUnit", isGreaterThan: 0)
.orderBy("totalUnit")
.orderBy("sellingPrice", descending: isDesc)
.limit(limit)
.get()
Maybe it's the problem with the orderBy("totalUnit") statement because after removing it, the query is returning the docs in sorted manner.
I checked, and I think the order is sorted according to totalUnit, but I want the list to be sorted according to the sellingPrice.
And I cannot remove the orderBy("totalUnit") statement, because of the limitations of firestore, I need the statement because of the one above it.
For example, this below isn't exactly what I am getting but it's enough to make you understand the problem I've been facing,
Sample Data -
Products---->
Product1 - { "tags" :[a], "totalUnit": 2, "sellingPrice": 1000}
Product2 - { "tags" :[a], "totalUnit": 0, "sellingPrice": 700}
Product3 - { "tags" :[a], "totalUnit": 0, "sellingPrice": 2000}
Product4 - { "tags" :[a], "totalUnit": 3, "sellingPrice": 2000}
Product5 - { "tags" :[a], "totalUnit": 2, "sellingPrice": 500}
So that Function should only return,
If in ascending order - Product5, Product1, Product4
If in descending order - Product4, Product1, Product5