gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 15:02:30 24 4
gpt4 key购买 nike

我正在尝试按照此 firebase 文档 https://firebase.google.com/docs/configure/ 从下面的两个 firebase 数据库中获取数据

     // 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/');

}
})

但我一直收到这个错误

code: "app/duplicate-app", message: "Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app)."

为什么会出现此错误,我该如何解决?

最佳答案

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

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

如果你想初始化第二个非默认应用程序,你将不得不通过将第二个参数传递给 initializeApp() 来为其命名。 :

firebase.initializeApp(secondaryAppConfig, "secondary");

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

关于javascript - 如何使用 Javascript 从多个 firebase 数据库中获取数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46291003/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com