通过以下方式启动 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/