且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何基于数据库仿真器更新使Firebase功能仿真器触发

更新时间:2023-12-06 07:50:09

您似乎刚刚忘记了项目/命名空间ID.

It looks like you may have just forgotten the project/namespace ID.

尝试将?ns = 参数添加到POST:

Try adding the ?ns= parameter to your POST:

POST
http://localhost:9000/a/path.json?ns="YOUR_PROJECT_ID"
{
  "some": "data"
}

仅在生产过程中,仿真功能会从写入单个数据库实例的操作中触发.

Emulated functions only trigger from writes to a single database instance, just like in production.

关于您的困惑点:

  • functions:shell 只是函数的REPL.它不会模拟任何其他服务(数据库,Firestore等).相反,您直接传递来自那些服务的数据.
  • 如果要测试功能<->数据库交互,请使用 emulators:start --only database,functions
  • 通常,使用 emulators:start 的规则是,我们全面模拟正在运行的内容.因此,例如,如果您正在运行函数和数据库"模拟器,则所有从函数的写入(通过 admin.database().... 都将被重定向到数据库模拟器.但是写入Firestore( admin.firestore()... )将尝试并投入生产,因为该模拟器未运行.
  • functions:shell is just a REPL for functions. It does not emulate any other services (Database, Firestore, etc). Instead you directly pass in the data that would come from those services.
  • If you want to test Functions <--> Database interactions use emulators:start --only database,functions
  • In general the rule with emulators:start is that we comprehensively emulate whatever is running. So for example if you're running the Functions and Database emulator, all writes from functions (through admin.database().... will be redirected to the Database emulator. But writes to Firestore (admin.firestore()...) will try and hit production because that emulator is not running.