![](/img/trans.png)
[英]Flutter Firestore create new Array every time function called
[英]Create new client for every operation to firestore?
我在 firestore Go 文档中看到了这样的示例。 我们是否必须为每个要进行 firestore 的操作创建如下所示的客户端,或者我们是否可以在应用程序启动期间创建一个客户端并使用相同的客户端来执行操作? 请告诉我。
ctx := context.Background()
client, err := firestore.NewClient(ctx, "project-id")
if err != nil {
// TODO: Handle error.
}
defer client.Close()
type State struct {
Capital string `firestore:"capital"`
Population float64 `firestore:"pop"` // in millions
}
wr, err := client.Doc("States/Colorado").Create(ctx, State{
Capital: "Denver",
Population: 5.5,
})
if err != nil {
// TODO: Handle error.
}
fmt.Println(wr.UpdateTime)
否。创建客户端一次并重新使用相同的客户端。 有关此帖子的更多详细信息 - Should a Firestore client be created per request with Google App Engine?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.