c# - Firestore 使用 C# 在 WPF 中写入批处理?
问题描述
我正在使用google-cloud-dotnet库在我的WPF程序中使用C#使用Firestore
我需要一次写大量文档,大约2000个文档..所以我必须找到一种比每次写一个文档更好的方法
找到WriteBatch类,并尝试以下方法:
var batch = new WriteBatch();
DocumentReference docRef = db.Document("cities/myCity");
batch = batch.Set(docRef, new {
Name = "Los Angeles",
Country = "USA",
State = "CA",
});
batch.CommitAsync();
但无法正确启动批处理,出现错误:
WriteBatch不包含采用 0 个参数的构造函数
那么您能否解释一下我应该如何启动稍后使用的批量写入?
解决方案
经过一番研究,我能够batch
成功使用 write,例如:
using Google.Cloud.Firestore;
// ...
System.Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "myCredentials.json");
FirestoreDb db = await FirestoreDb.CreateAsync("myProject");
var batch = db.StartBatch();
DocumentReference docRef = db.Document("cities/myCity");
batch = batch.Set(docRef, new {
Name = "Los Angeles",
Country = "USA",
State = "CA",
});
batch.CommitAsync();
推荐阅读
- php - 如何在安装过程中更改 wp-cli 中的发件人地址?
- c++ - 谷歌测试:未知文件失败
- c++ - OpenCV 3D 相机校准与四个相机
- windows - 如何为单个 Windows 服务指定或覆盖自定义环境变量
- unit-testing - 需要对 golang 错误 fs.PathError 进行单元测试
- html - 未从 site.css 应用 CSS
- java - 如何使用另一个列表清除一个列表
- r - 在 R 中使用带有 httr 的 paste0 函数
- rest - 如何阻止垃圾邮件发送者通过您的 API 使用虚假电子邮件滥用注册服务
- rest - REST:查询字符串以通过它的数组属性查询资源