I know you can pull the server timestamp in web, ios, and android - but what about the new Cloud Functions for Firebase? I can\'t figure out how to get the server timestamp
It's in the documentation August 16, 2020.
https://cloud.google.com/firestore/docs/manage-data/add-data#server_timestamp
// Get the `FieldValue` object
const FieldValue = admin.firestore.FieldValue;
// Create a document reference
const docRef = db.collection('objects').doc('some-id');
// Update the timestamp field with the value from the server
const res = await docRef.update({
timestamp: FieldValue.serverTimestamp()
});
Here's how I used it in my code:
const createUserDoc = (user) => {
const FieldValue = admin.firestore.FieldValue
return db.collection('users').doc(user.uid).set({
memberSince: FieldValue.serverTimestamp(),
})
}