Reputation: 1
How I can order data doc by two field, My app have a stream builder and I want order the data by the time that wrote and if the todo important so there is two field in docs one for time and there is boolen value i want the data order by the time and if the data important that is mean the boolen true to be in the top of the list of stream and when i add data will show ender it. this the code I used for strem
final FirebaseFirestore firestore;
DataBase({this.firestore});
Stream streamTodos({String uid}) {
try {
return firestore
.collection("homeNeeds")
.doc(uid)
.collection('homeNeeds')
.orderBy('time', descending: true)
.snapshots();
} catch (e) {
return e;
}
}
// i tried to put tow orderBy('time', descending: true).orderBy('pin', descending: true) and it doesn't work the snap shot return empty
Upvotes: 0
Views: 330
Reputation: 1
I solved this problem by adding Indexes in cloud firestore and that option allow you to use tow orderby in the same code
Upvotes: 0
Reputation: 168
You can use multi_sort: ^3.0.0 in this case.
https://pub.dev/packages/multi_sort
Upvotes: 0
Reputation: 1309
it appears that is not as simple as saying you can or you can not, it depends on your specific case, but most likely you'll have to do it client-side.
There is another question like this one here:
Upvotes: 0