Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
688 views
in Technique[技术] by (71.8m points)

firebase - Ordering data does not actually order anything

I'm trying to get a dataset of messages out of my firebase database and want the messages sorted by added/timestamp. But for some reason no orderby I put in the code is actually used. I tried doing these 2 things.

_messagesRef = FirebaseDatabase.instance.reference().child('messages/'+key);
_membersSubscription = _messagesRef
    .orderByChild('timestamp')
    .onValue//On valuechange
    .listen((Event event) => _messagesSubscriptionCallback(event)); 

 _messagesRef = FirebaseDatabase.instance.reference().child('messages/'+key);
 _membersSubscription = _messagesRef
    .orderByKey()
    .onValue//On valuechange
    .listen((Event event) => _messagesSubscriptionCallback(event)); 

Both give me back the same dataset that is not ordered by timestamp or key in the callback. I've added the output underneath

{  
   -LA-Aw6crEAV53LxdujP:{  
      sender:1508,
      message:test s9 2,
      timestamp:1523642778089
   },
   -LA-Arby61T1UG5URMn6:{  
      sender:1508,
      message:test s9,
      timestamp:1523642759679
   },
   -LA-AyC7F8KAqceZBE3j:{  
      sender:1509,
      message:test emu 1,
      timestamp:1523642786632
   },
   -LA22WiUfL2tbh7-OjtM:{  
      sender:1508,
      message:Blaj,
      timestamp:1523690904480
   },
   -LA-B29RRXbdOPT1mG7m:{  
      sender:1508,
      message:tesy3,
      timestamp:1523642806940
   }
}

This is how the data should be.

enter image description here

I hope someone can help me with this issue. I think I might misunderstand how ordering data works with Firebase

Kind regards, Namanix

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...