如何在不使用实时数据库但使用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
})
}
Run Code Online (Sandbox Code Playgroud) javascript firebase google-cloud-functions google-cloud-firestore
我想使用对Firestore createDocument方法的REST调用来插入文档。字段之一是应在服务器上设置的时间戳字段。使用Android SDK,就像用Date字段注释@ServerTimestamp并保持为空一样简单-现在如何在REST中做到这一点?
{
"fields": {
"timezoneId": {
"stringValue": "Europe\/London"
},
"city": {
"stringValue": "London"
},
"timestamp": {
"timestampValue": "???"
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试使用null,,0空字符串timestamp-一切都会失败,并出现要求标准RFC3339格式的错误(例如2018-01-31T13:50:30.325631Z)。我可以使用任何占位符值,或以任何方式获取该时间戳记吗?