How can we get a server timestamp, without using the realtime database but using instead Firestore ?
import * as functions from 'firebase-functions'
import { Firestore } from '@google-cloud/firestore'
const db = new Firestore()
export let testIfMatch = functions.firestore
.document('users/{userId}/invites/{invitedUid}')
.onCreate(event => {
let invite = <any>event.data.data()
if (invite.accepted == true) {
return db.collection('matches').add({
friends: [userId, invitedUid],
timestamp: doc.readTime // <--- not exactly the actual time
})
}
Here's a slightly more concise way of doing it:
import * as admin from "firebase-admin"
const timestamp = admin.firestore.FieldValue.serverTimestamp();
Use server timestamp with Firestore is little different:
if it's not working you can edit the
var FieldValue = require("firebase-admin").FieldValue;
withvar FieldValue = require("firebase-admin").firestore.FieldValue;