python - 通过 `firebase` 和 `gcloud` 启动 firestore 模拟器的区别?

标签 python firebase google-cloud-platform google-cloud-firestore gcloud

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

firebase emulators:start --only firestore
和:
gcloud beta emulators firestore start
这两个选项都允许我的 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)
我自己注意到的一个区别是 firebase似乎尊重我的firebase.json ,特别是像这样指定的主机端口:
{
  "emulators": {
    "firestore": {
      "port": "8081"
    }
  }
}
另一方面,gcloud忽略 firebase.json而是选择一个随机端口,除非我明确地通过 --host-port 传递一个端口.这是两者之间更大差异的一部分,还有哪些其他差异?

最佳答案

我一直在查看这两种工具的文档,它们几乎做同样的事情。
使用 Firebase tool您可以为多个 Firebase 产品启动模拟器,而 gcloud command允许您启动 GCP 模拟器。 Firestore 只是他们共同拥有的产品,因此它们的效用应该相同或相似。
关于功能差异,firebase提供 --import--export-on-exit允许您在模拟 session 之间保存和恢复数据的标志。它还提供了一种可视化 security rules 的方式。正在处理当前的查询。
除了这些功能,我会注意到设置端口和规则文件的不同方法:

  • firebase emulators使用 firebase.json 文件。
  • gcloud beta emulators使用标志 --host-port --rules 实现相同的功能。

  • 请注意 Firestore emulator GCP 是在 beta stage 上因此,它的官方支持可能有限,并且可能会发生变化。还要注意如何,在 GCP's Firestore documentation ,使用 Firebase CLI 代替 gcloud。
    最后,您应该使用您喜欢的工具,因为它们都朝着模拟 Firestore 的相同目标努力。如果您已经在使用 Firebase CLI,我建议您继续使用它;如果您正在使用 gcloud ,用那个。

    关于python - 通过 `firebase` 和 `gcloud` 启动 firestore 模拟器的区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63433943/

    相关文章:

    python - 使用 Builder.load_string 在 Kivy 应用程序上显示变量

    firebase - Firebase Cloud Functions 如何确认 Cloud pub/sub

    python-3.x - 将图形写入 Google Cloud Storage 而不是本地驱动器

    python - 如何将表的列名提取到列表或元组

    python - Pytest Flask 请求推荐人

    python - 如何关闭端口并尽快终止所有事件连接?

    python - 如何在CNN中将OpenCV函数中的1d数组与向量展平

    java - 如何在 Firestore 查询的组合任务中获取最后一个可见的 DocumentSnapshot?

    ios - 如何在 Google Cloud Platform 中启动 macOS 实例?我需要 mac 实例来运行 xamarin ios 应用程序的 xcode 构建

    google-cloud-platform - GCP 无服务器网络端点组不显示 Cloud Run 服务