Cloud Firestore REST API-添加服务器时间戳 [英] Cloud Firestore REST API - Add server timestamp
问题描述
我正在使用具有ESP8266-01模块的Arduino,通过具有以下负载的createDocument API将值上传到Cloud Firestore数据库:
I'm using an Arduino with an ESP8266-01 module to upload a value to a Cloud Firestore database using the createDocument API with the following payload:
{
"fields": {
"distance": {
"integerValue": "555"
}
}
}
我对这样的路由执行POST请求:
I do a POST-request to a route like this:
https://firestore.googleapis.com/v1beta1/projects/<MY_PROJECT>/databases/(default)/documents/<SOME_COLLECTION>?key=MY_VERY_SECRET_KEY
这一切都可行,但是我也想添加服务器时间戳.我在这里找到了一些关于stackoverflow的答案,但是我无法使它们中的任何一个起作用.
That all works, but I would like to add the server timestamp as well. I've found a few answers here on stackoverflow, but I have not been able to make any of them work.
如何将服务器时间戳添加到创建的文档中?我想要创建以下内容:
How can I add the server timestamp to the created document? What I want is for the following to be created:
{
"fields": {
"distance": {
"integerValue": "555"
},
"timestamp" : {
"DATETIME": SERVER_TIMESTAMP
}
}
}
任何帮助表示赞赏.
推荐答案
最后我要做的是:
对这样的路线的POST请求:
A POST request to a route like this:
https://firestore.googleapis.com/v1beta1/projects/<MY_PROJECT>/databases/(default)/documents:commit?&key=<MY_VERY_SECRET_KEY>
具有以下有效负载:
{
"writes": [
{
"update": {
"name": "projects/<MY_PROJECT>/databases/(default)/documents/<COLLECTION_ID>/<DOCUMENT_ID>",
"fields": {
"distance": {
"integerValue": "555"
}
}
}
},
{
"transform": {
"document": "projects/<MY_PROJECT>/databases/(default)/documents/<COLLECTION_ID>/<DOCUMENT_ID>",
"fieldTransforms": [
{
"fieldPath": "servertime",
"setToServerValue": "REQUEST_TIME"
}
]
}
}
]
}
我在其中生成新的DOCUMENT_ID(例如GUID),而不是让Cloud Firestore为我生成一个.
Where I generate a new DOCUMENT_ID (e.g. a GUID) instead of having cloud firestore generate one for me.
这篇关于Cloud Firestore REST API-添加服务器时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!