[英]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.