Google Firestore - how to get document by multiple ids in one round trip?

前端 未结 11 1799
余生分开走
余生分开走 2020-11-21 22:49

I am wondering if it\'s possible to get multiple documents by list of ids in one round trip (network call) to the Firestore.

11条回答
  •  迷失自我
    2020-11-21 23:18

    You could use a function like this:

    function getById (path, ids) {
      return firestore.getAll(
        [].concat(ids).map(id => firestore.doc(`${path}/${id}`))
      )
    }
    

    It can be called with a single ID:

    getById('collection', 'some_id')
    

    or an array of IDs:

    getById('collection', ['some_id', 'some_other_id'])
    

提交回复
热议问题