简体   繁体   English

当我使用 firebase.database().goOnline(); 我得到一个错误

[英]when i use firebase.database().goOnline(); I get an error

this is my code这是我的代码

admin.initializeApp({...});

var db = admin.database();
let ref = db.ref(...);

await ref.once("value",function () {...},);

firebase.database().goOffline();
firebase.database().goOnline();

 ref.on("value",function () {...},);
);

when i use firebase.database().goOnline();当我使用 firebase.database().goOnline(); I get an error我得到一个错误

Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).
    at app

You're mixing two ways of addressing Firebase.您混合使用两种寻址方式 Firebase。

You can access Firebase through:您可以通过以下方式访问 Firebase:

  1. Its client-side JavaScript SDK, in which case the entry point is usually called firebase .它的客户端 JavaScript SDK,在这种情况下,入口点通常称为firebase
  2. Its server-side Node.js SDK, in which case the entry point is usually called admin .它的服务器端 Node.js SDK,在这种情况下,入口点通常称为admin

Now you initialize admin , but then try to access firebase.database() .现在您初始化admin ,然后尝试访问firebase.database() And since you did call admin.initializeApp that's where the error comes from.并且由于您确实调用admin.initializeApp这就是错误的来源。

My guess is that you're looking for admin.database().goOnline() or db.goOnline() .我的猜测是您正在寻找admin.database().goOnline()db.goOnline()

Also note that there is no reason to toggle goOffline() / goOnline() in the way you do now, and you're typically better off letting Firebase manage that on its own.另请注意,没有理由像现在这样切换goOffline() / goOnline() ,通常最好让 Firebase 自行管理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM