简体   繁体   English

Firestore:如何更新现有字段

[英]Firestore: How to update an existing field

I am trying to update a Firestore document field I have set earlier through REST API. 我正在尝试更新我之前通过REST API设置的Firestore文档字段。

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. 现在,我希望能够通过REST API更新字段“ testfield”(该用户数据的一部分)。

I have sent a HTTP POST Request to https://firestore.googleapis.com/v1/projects/[MY_PROJECT_ID]/databases/(default)/documents/users?documentId=-example 我已将HTTP POST请求发送到https://firestore.googleapis.com/v1/projects/[MY_PROJECT_ID]/databases/(default)/documents/users?documentId=-example MY_PROJECT_ID] / databases /( https://firestore.googleapis.com/v1/projects/[MY_PROJECT_ID]/databases/(default)/documents/users?documentId=-example documents / users 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. 根据Firestore REST API文档 ,您可以使用PATCH请求来更新字段。

A POST isn't going to work, since that's used for creating new documents. POST不起作用,因为它用于创建新文档。 That explains the error that the document already exists. 这就解释了文档已经存在的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 set 方法更新 Firestore 中的现有文档 - How to update existing document in firestore using set method 如何使用 flutter 更新 Firestore 中所有文档的单个字段? - How to update a single field of all documents in firestore using flutter? Upsert 仅插入而不更新现有字段 - Upsert Only inserts and does not update the existing field Firestore 多对多关系 - 如何更新数据? - Firestore many to many relationships - How to update data? 如何在 Firestore 的父 map 字段中添加新的 map 字段? - How to add a new map field inside a parent map field in Firestore? PHP-发布带有添加到现有值的更新数据库字段 - PHP - Issue update db field with add to existing value 当HTML表单字段之一提交为空白(其中所有询问列的默认值为NULL)时,如何更新现有的MySQL表? - How to update existing MySQL table when one of the HTML form field is submitted blank where default value for all asked columns is NULL? pymongo:如何将字段插入到已经存在的文档中 - pymongo: How to insert a field to an already existing document 如何将数据更新到 firebase 中的现有节点 - How to update data to existing node in firebase 如何在 Firestore 索引配置文件中添加单字段豁免 - How to add Single-field Exemptions in Firestore Index Config File
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM