如何查询地图对象(即Firebase中的文档ID)?

时间:2019-10-09 04:01:33

标签: javascript firebase google-cloud-firestore

我试图获取有效载荷>(随机文档ID)对象内的所有字段名。

enter image description here

目前,我正在通过以下方式获取其他收藏集:

async fetchPage() {
  const query = firebase
    .firestore()
    .collection('PAGES')
    .where('type', '==', 'page')
  try {
    const { docs } = await query.get()

    this.pageIndex = docs.map((doc) => {
      if (doc && doc.exists) {
        this.items = doc.data()
      }
      let { id } = doc
      const data = doc.data()
      return { id, ...data }
    })

    console.log('Loaded items', this.items)
  } catch (error) {
    throw new Error('Something gone wrong!')
  }
},

第一个问题是:查询对象的最佳实践是什么?我在firebase文档中阅读了this,但并没有导致我尝试这种方法而获得任何结果。

第二个问题,由于有效负载的子对象是其文档的实际ID,因此我必须使用哪种方法声明要查找的内容,例如有效负载>文档ID>内容:“这是一些内容”? / p>

1 个答案:

答案 0 :(得分:0)

以下是一些有关Firestore运作方式的信息,可能对您如何改善数据库中的查询有帮助。

这里是Firebase documentation about queriesQuery Client Library

这是一篇涉及slow queries原因的文章。

关于第二个问题,您可以获取整个文档的快照,然后必须遍历数据。

让我知道这是否对您有帮助。