Please, I need your help to get the server timestamp from Firebase version 9.
I've tried to follow the same approach as for Firebase v8 : firebase.firestore.FieldValue.serverTimeStamp()
but didn't work for version 9.
Is there any way to do the same thing in Firebase version 9 ?
CodePudding user response:
It's discussed in the documentation. Just import serverTimestamp
.
import { updateDoc, serverTimestamp } from "firebase/firestore";
const docRef = doc(db, 'objects', 'some-id');
// Update the timestamp field with the value from the server
const updateTimestamp = await updateDoc(docRef, {
timestamp: serverTimestamp()
});