Cloud Firestore REST API - Add server timestamp

后端 未结 1 624
庸人自扰
庸人自扰 2021-01-24 02:42

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:

{
    \"         


        
1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-24 03:21

    What I ended up doing in the end was the following:

    A POST request to a route like this:

    https://firestore.googleapis.com/v1beta1/projects//databases/(default)/documents:commit?&key=

    With the following payload:

    {
        "writes": [
            {
                "update": {
                    "name": "projects//databases/(default)/documents//",
                    "fields": {
                        "distance": {
                            "integerValue": "555"
                        }
                    }
                }
            },
            {
                "transform": {
                    "document": "projects//databases/(default)/documents//",
                    "fieldTransforms": [
                        {
                            "fieldPath": "servertime",
                            "setToServerValue": "REQUEST_TIME"
                        }
                    ]
                }
            }
        ]
    }
    

    Where I generate a new DOCUMENT_ID (e.g. a GUID) instead of having cloud firestore generate one for me.

    0 讨论(0)
提交回复
热议问题