リアルタイム データベースを使用せずに 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
})
}
ベストアンサー1
Firestore でサーバー タイムスタンプを使用する方法は少し異なります。
// Get the `FieldValue` object
var FieldValue = require("firebase-admin").FieldValue;
// Create a document reference
var docRef = db.collection('objects').doc('some-id');
// Update the timestamp field with the value from the server
var updateTimestamp = docRef.update({
timestamp: FieldValue.serverTimestamp()
});
var FieldValue = require("firebase-admin").FieldValue;
うまくいかない場合は、var FieldValue = require("firebase-admin").firestore.FieldValue;