How can I use multiple order by in real time database flutter to order data by specific field? [duplicate]

我的未来我决定 提交于 2021-01-29 17:31:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!