I'm succesfully adding those data to firestore with my visual studio c# application using the library:
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);
CodePudding user response:
Assuming you're using the Google.Cloud.Firestore
library, I'd expect you to be able to use 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);