问题
I am trying to short "realtime database" result according to "date" in flutter. But I cant use multiple orderByChild('child_name'). It throw an error. My code is
final String path = 'jsondata';
final _dbRef = FirebaseDatabase.instance.reference();
_dbRef.child(path)
.orderByChild('trade_code').equalTo('GP')
.once()
.then((DataSnapshot snapshot) {
snapshot.value.forEach((key, value) {
print(value);
});
});
The result is Result
Now I want to sort the data by Date. How can I do that?
回答1:
It's not possible to use multiple oder at the same time in Firebase Realtime Database
. Please check the following doc:
Firebase Realtime Database Query
To achieve that type of complex query I prefer that you should migrate from the Realtime Database
to Firebase Cloud Firestore
. Check the following resource:
Simple and Complex Dynamic Query in Could Firestore
Your Firestore instance would be:
FirebaseFirestore.instance
.collection('products')
.where('trade_code', isEqualTo: 'GP')
.orderBy('date')
来源:https://stackoverflow.com/questions/63712262/how-can-i-use-multiple-order-by-in-real-time-database-flutter-to-order-data-by-s