I am creating a Spring Boot application and I have a timestamp variable in Firestore DB I want to send date in that field. How can I do that?
This is my service I am sending data to Firebase
public Patient addPatient(Patient patients) throws InterruptedException, ExecutionException {
Firestore dbFirestore = FirestoreClient.getFirestore();
ApiFuture<WriteResult> collectionApiResult = dbFirestore.collection(this.fireStoreCollection).document(patients.getUserId()).set(patients);
return patients;
}
As mentioned by @Zeenath SN above, this post has your answer.
You can use ServerTimestamp annotation. Try changing
private Timestamp dob;
to
private Date dob;
in your code.
Alternatively, as below:
If you want to write a timestamp field, and you can't use a server timestamp, you will need to either provide a regular Java Date object, or a Firebase Timestamp object. Either of these types of values will convert to a timestamp field in the document.
When you query for the document, the field will always show up in the document snapshot as a Timestamp type object.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.