Home > other >  orderby with multiple data received from query in flutter firestore
orderby with multiple data received from query in flutter firestore

Time:07-11

i have 2 collections . first collection: Categories - with the field 'position' and the field 'name' for example:

  • pos: 1 ----- name: vegetables
  • pos: 2 ----- name: fruits

The other collection are my products with include the names of the products and a field 'category' which contains the name of the categories for example:

  • name: Banana ------ category: fruits
  • name: potato ------ category: vegetables

In my app the user can in reorderableListView the categorys to his needs. Now, i try to make a query on the category collection: for example:

FirebaseFirestore.instance.collection('categories').orderby('pos').get(); 

so i will receive the result in the right order.

After that i want to query the products to receive them in the sortorder than the categories result.

How is that possible??

....orderby(?.RESULT FROM CATEGORY QUERY ?) 

i dont know what to write inside the orderby statement??? is something like this possible? or can i build the query programmaticaly?

CodePudding user response:

There's no specific API that allows this type of query, so your options are:

  1. Retrieve the results one by one (or in batches of up to 10 using an IN query on the document ID) and then re-order them in your application code.
  2. Retrieve the results one by one in the right order already.
  • Related