[英]Firestore write batch in WPF using C#?
I'm using google-cloud-dotnet library to work with Firestore in my WPF program using c#我正在使用google-cloud-dotnet库在我的WPF程序中使用c#使用Firestore
I need to write large amount of documents at once, about 2000 documents.. So I have to find a way better than writing a single document each time我需要一次写大量文档,大约2000个文档..所以我必须找到一种比每次写一个文档更好的方法
Found WriteBatch class, and tried the following:找到WriteBatch class,尝试如下:
var batch = new WriteBatch();
DocumentReference docRef = db.Document("cities/myCity");
batch = batch.Set(docRef, new {
Name = "Los Angeles",
Country = "USA",
State = "CA",
});
batch.CommitAsync();
but couldn't initiate the batch correctly, getting an error:但无法正确启动批处理,出现错误:
WriteBatch does not contain a constructor that takes 0 arguments
WriteBatch不包含取 0 arguments 的构造函数
So could you please explain how should I initiate the batch writing to be used later?那么您能否解释一下我应该如何启动批处理写入以供以后使用?
After some researching I was able to use batch
write successfully, example :经过一番研究,我能够成功使用
batch
写入,例如:
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.