How to query one field then order by another one in Firebase cloud Firestore?

前端 未结 6 977
粉色の甜心
粉色の甜心 2021-02-13 04:14

I\'m struggling to make a (not so) complex query in firebase cloud firestore.

I simply need to get all docs where the id field ==

6条回答
  •  花落未央
    2021-02-13 04:28

    Please check the doc. It says

    However, if you have a filter with a range comparison (<, <=, >, >=), your first ordering must be on the same field

    you can try this code

    db.firestore().collection('comments')
        .where("postId",'==',idOfThePost)
        .orderBy('postId')
        .orderBy('date','asc').limit(10).get().then( snapshot => {
           .....
         })
    

提交回复
热议问题