我正在尝试使用REST API在云Firestore中执行PATCH Opeartion.
Im trying to perform PATCH Opeartion in cloud firestore using REST API.
这是我的请求正文
`{ "fields": { "name": { "stringValue":"Dinesh" } } }`当我发出请求时,文档内的所有现有字段都将被删除,只有名称字段将被更新.他们在文档中提供了文档掩码文档掩码.但是我不明白它是如何工作的,也都无法为此找到任何样本.有人知道如何只更新文档中的一个字段而不影响其他字段吗?
When i fire the request , All the existing fields inside the document are getting deleted and only the name field is getting updated. In the Documentation they have given the Document Mask Document Mask. but i dont understand how it works , neither im able to find any samples for that. Somebody know how to update only one field inside the document without affecting other fields ?
推荐答案在没有DocumentMask对象的情况下,修补程序方法默认为用请求正文替换Firestore Document,而不是更新提交的字段并保留省略的字段.
Without a DocumentMask object, the patch method defaults to replacing the Firestore Document with the request body rather than updating the submitted fields and retaining omitted fields.
DocumentMask作为updateMask参数提交,其中包含要修补的fieldPaths.花费了一段时间,但感谢这个答案,并且我做了很多尝试,发现updateMask对象的每个fieldPath属性都需要分别单独包含在请求网址的查询字符串中:
The DocumentMask is submitted as an updateMask parameter containing the fieldPaths to be patched. It took a while but thanks to this answer and a lot of attempts I figured out that each fieldPath property of the updateMask object needs to be individually included in the query string of the request url:
firestore.googleapis/v1beta1/projects/{projectId}/databases/{databaseId}/documents/{document_path}?updateMask.fieldPaths=status&updateMask.fieldPaths=title
其中status和title是请求正文中的两个字段.请注意,如果查询字符串中省略了请求正文中包含的字段,则这些字段将保持不变.
Where status and title are two fields in the request body. Note that fields included in the request body are disregarded if they are omitted from the query string, remaining unchanged.
更多推荐
Firestore使用Rest API更新文档字段
发布评论