[英]c# firestore add timestamp field in visual studio project
I'm succesfully adding those data to firestore with my visual studio c# application using the library:我使用库成功地将这些数据添加到我的 Visual Studio C# 应用程序的 Firestore:
Google.Cloud.Firestore Google.Cloud.Firestore
now, I need to add a new field the timestamp but how to decleare it?现在,我需要在时间戳中添加一个新字段,但如何清除它? I haven't find a property for it.
我还没有找到它的属性。 Any suggestion?
有什么建议吗?
Thanks谢谢
CollectionReference coll = database.Collection("reports");
Dictionary<string, object> data1 = new Dictionary<string, object>()
{
{"fileId", fileId},
{"fileName", fileName},
{"type", type},
{"userId", userId},
{"url", urlReport },
{"plantId", plantId },
};
coll.AddAsync(data1);
Assuming you're using the Google.Cloud.Firestore
library, I'd expect you to be able to use FieldValue.ServerTimestamp
:假设您使用的是
Google.Cloud.Firestore
库,我希望您能够使用FieldValue.ServerTimestamp
:
CollectionReference coll = database.Collection("reports");
Dictionary<string, object> data1 = new Dictionary<string, object>()
{
{"fileId", fileId},
{"fileName", fileName},
{"type", type},
{"userId", userId},
{"url", urlReport },
{"plantId", plantId },
{"timestamp", FieldValue.ServerTimestamp}
};
await coll.AddAsync(data1);
Note that the library supports anonymous types as well, so it would be simpler to write:请注意,该库也支持匿名类型,因此编写起来会更简单:
CollectionReference coll = database.Collection("reports");
var data1 = new { fileId, fileName, type, userId,
url = urlReport, plantId, timestamp = FieldValue.ServerTimestamp };
await coll.AddAsync(data1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.