通过以下方式启动firestore emulator有什么区别:
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
标志,允许您在模拟会话之间保存和恢复数据。它还提供了一种可视化security rules如何处理当前查询的方法除了这些功能外,我还要注意设置端口和规则文件的不同方法:
firebase emulators
使用^{gcloud beta emulators
使用标志^{请注意,GCP上的Firestore emulator位于beta stage上,因此其官方支持可能有限,可能会发生更改。还请注意,在GCP's Firestore documentation上,Firebase CLI是如何代替gcloud使用的
最后,您应该使用首选工具,因为它们都朝着模拟Firestore的相同目标工作。如果您已经在使用Firebase CLI,我建议您继续使用它;如果您正在使用
gcloud
,请使用该选项相关问题 更多 >
编程相关推荐