通过“firebase”和“gcloud”启动firestore模拟器之间的区别?

Mar*_*hac 6 python firebase google-cloud-platform gcloud google-cloud-firestore

通过以下方式启动 firestore 模拟器有什么区别:

firebase emulators:start --only firestore
Run Code Online (Sandbox Code Playgroud)

和:

gcloud beta emulators firestore start
Run Code Online (Sandbox Code Playgroud)

这两个选项都允许我的 python 应用程序实现与数据库的连接,如下所示:

import google
from google.cloud import firestore

os.environ["FIRESTORE_EMULATOR_HOST"] = "localhost:8081"
os.environ["FIRESTORE_EMULATOR_HOST_PATH"] = "localhost:8081/firestore"
os.environ["FIRESTORE_HOST"] = "http://localhost:8081"

credentials = mock.Mock(spec=google.auth.credentials.Credentials)
client = firestore.Client(credentials=credentials)
Run Code Online (Sandbox Code Playgroud)

我自己注意到的一个区别是,它firebase似乎尊重我的firebase.json,特别是指定的主机端口,如下所示:

{
  "emulators": {
    "firestore": {
      "port": "8081"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

另一方面,gcloud忽略firebase.json并选择随机端口,除非我明确地通过 传递端口--host-port。这部分是两者之间较大的区别吗?还有哪些其他区别?

Ajo*_*dat 7

我一直在查看这两个工具的文档,它们的作用几乎相同。

使用Firebase 工具,您可以启动多个 Firebase 产品的模拟器,而gcloud 命令允许您启动 GCP 模拟器。Firestore 只是它们共同的产品,因此它们的实用程序应该相同或相似。

关于功能差异,firebase提供了--import--export-on-exit标志,允许您在模拟会话之间保存和恢复数据。它还提供了一种可视化安全规则如何处理当前查询的方法。

除了这些功能之外,我还要注意设置端口和规则文件的不同方法:

请注意, GCP 上的Firestore 模拟器正处于测试阶段,因此它的官方支持可能有限,并且可能会发生变化。另请注意,在GCP 的 Firestore 文档中,如何使用 Firebase CLI 而不是 gcloud。

最后,您应该使用您喜欢的工具,因为它们都致力于模拟 Firestore 的相同目标。如果您已经在使用 Firebase CLI,我建议您继续使用它;如果您正在使用gcloud,请使用它。