简体   繁体   中英

Firestore: How to update an existing field

I am trying to update a Firestore document field I have set earlier through REST API.

I have a document (users) which contains all user data. Now I like to be able to update the field 'testfield' - which is part of this user data - through REST API.

I have sent a HTTP POST Request to https://firestore.googleapis.com/v1/projects/[MY_PROJECT_ID]/databases/(default)/documents/users?documentId=-example

with request body

{
    "fields": {
        "testfield": {
            "booleanValue": true
        }
    }
}

All I get by now is an error message telling me that the document already exists, what I know, since I am trying to update this document.

According to the Firestore REST API documentation , you use a PATCH request to update a field.

A POST isn't going to work, since that's used for creating new documents. That explains the error that the document already exists.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM