连接Firebase数据库调用 [英] Concatenate Firebase DB calls

查看:57
本文介绍了连接Firebase数据库调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Firebase Cloud Function,必须根据提供的ID获取更多数据,请参见下面的代码:-

I have a Firebase Cloud Function where I am having to get more data based on an ID provided, see code below:-

return admin.firestore().collection('companies').doc(snap.data().companyId).get().then((company) => {
    return admin.firestore().collection('customers').doc(snap.data().companyId).get().then((customer) => {
         console.log(company, customer);
    })
})

有没有一种方法可以组合这些调用,这样我就不必在每次需要获取数据时都对数据库进行2次调用?

Is there a way I can combine these call so I don't have to make 2 calls to the DB every time I need to get the data?

这将有助于降低成本并阻止拨打昂贵的电话.

This would help lower costs and help stop making expensive calls.

此示例仅具有两个调用级别,根据我从云功能内部的数据库中获取的信息,有时可以进行多达三个调用.

This example only has two levels of calls, some times this can go as far as three calls depending on what information I require from the DB inside my cloud function.

任何帮助将不胜感激.

推荐答案

您不能同时查询两个不同的集合.您要么执行多个查询,要么提前将数据加入单个集合以查询包含所有数据的数据.这称为非规范化",在没有类似SQL的联接操作的NoSQL数据库中很常见.

You can't query two different collections at the same time. You either have to perform multiple queries, or join your data ahead of time into a single collection to query that contains all the data. This is called "denormalization", and is common in NoSQL databases that have no SQL-like join operations.

这篇关于连接Firebase数据库调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆