如何使用Javascript从多个firebase数据库中获取数据?

时间:2017-09-19 02:48:58

标签: javascript firebase firebase-realtime-database

我正在尝试从以下两个firebase数据库中获取数据#{3}}

     // Initialize Firebase
var marketplaceconfig = {
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: ""
};
firebase.initializeApp(marketplaceconfig);


var secondaryAppConfig = {
apiKey: "",
authDomain: "",
databaseURL: "",
projectId: "",
storageBucket: "",
messagingSenderId: ""
};
firebase.initializeApp(secondaryAppConfig);

var secondary = firebase.initializeApp(secondaryAppConfig, "secondary");

我引用了辅助数据库,如下所示

firebase.auth().onAuthStateChanged((user) => {
if (user) {
     PersonalAsstDatabase = secondary.database();


    var BusinessesId = firebase.auth().currentUser.uid;
    // var selectedJob = JobId.value ;

    var deptref = PersonalAsstDatabase.ref('/Businesses/' + BusinessesId + '/Inventory/');

}
})

但我一直收到此错误

  

代码:“app / duplicate-app”,消息:“Firebase:名为'[DEFAULT]'的Firebase应用程序已经存在(app / duplicate-app)。”

为什么我会收到此错误以及如何解决?

1 个答案:

答案 0 :(得分:1)

您尝试初始化默认应用两次:

firebase.initializeApp(marketplaceconfig);
firebase.initializeApp(secondaryAppConfig);

如果您想要初始化第二个非默认应用,那么您必须通过将第二个参数传递给initializeApp()来为其命名:

firebase.initializeApp(secondaryAppConfig, "secondary");

请务必阅读initializing multiple apps上的文档,以便更好地了解如何继续。