javascript - 如何从不同的 Firebase 项目获取数据?

标签 javascript firebase google-cloud-firestore

场景 我使用命令行工具在 firebase 中创建了两个项目。第一个站点(比如 A)是一个使用托管、firestore、云功能和身份验证的 Web 应用程序。第二个站点(比如 B)是一种管理门户,它应该能够显示站点 A 中的所有数据。站点 B 使用与站点 A 不同的身份验证。

注意将来将会创建更多类似站点 A 的站点,而站点 B 仍将是所有站点的管理门户。

问题如何将 Firebase 中一个项目的数据转移到其他项目?

PS 我知道 SO 不允许这样做,但如果有更好的方法来做到这一点,我会很高兴知道。

最佳答案

您必须多次初始化 Firebase,每个项目一次。根据documentation :

// Initialize the default app
firebase.initializeApp(defaultAppConfig);

// Initialize another app with a different config
var otherApp = firebase.initializeApp(otherAppConfig, "other");

console.log(firebase.app().name);  // "[DEFAULT]"
console.log(otherApp.name);        // "other"

// Use the shorthand notation to retrieve the default app's services
var defaultStorage = firebase.storage();
var defaultDatabase = firebase.database();

// Use the otherApp variable to retrieve the other app's services
var otherStorage = otherApp.storage();
var otherDatabase = otherApp.database();

关于javascript - 如何从不同的 Firebase 项目获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51117459/

相关文章:

javascript - 模态弹出窗口在 UpdatePanel 中不起作用

javascript - 如何减少带有缩放内容的 div 的可滚动高度?

firebase - Firestore云函数: cannot read property 'userId' of undefined

firebase - 无法从数据库获取DataSnapshot并获取空值

android - 尝试从 Firestore 加载时应用程序关闭

javascript - 用于检查未使用的 CSS/JavaScript 选择器的 NetBeans 插件?

javascript - 从另一个函数设置组件的状态

android - iOS/Android firebase 后台同步

javascript - Cloud Function 中的 Firestore 更新出错

flutter - 添加 firestore 文档时更新 ListView.builder itemCount