Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

firebase - How to order data from Firestore in Flutter, orderBy not ordering correct

I'm building an app where the users can write into my db and ask questions to other users, like a doctor app. Where the doctors can answer the questions.

I wanna order the questions by date, where I would like to order the questions by newest, and also the most popular.

I try to order the newest by the following:

date: "29 September 2019"

Firestore.instance
        .collection("Questions")
        .orderBy("date", descending: true) // 1 will be last, 31 will be latest
        .snapshots(),

But that seem not to work. So I wonder how I could order the data correctly from my query from firebase. Or do I have to store the date as a long in the firebase and then convert it maybe?

Also, I would like to order the most popular questions, based on how many users have watched that particular questions by:

questionsView: "3", questionsView: "1032" etc

Firestore.instance
        .collection("Questions")
        .orderBy("questionsView")
        .snapshots(),

But neither does this do the ordering correctly.

I saw a great post from the legendery Frank von Puffen but I didn't really understand that, so I wonder if somebody could help me out on this.

Here's his post: Ordering Data In FireStore

Best regards, Rusben

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...