Firestore使用Rest API更新文档字段

编程入门 行业动态 更新时间:2024-10-21 17:34:20
本文介绍了Firestore使用Rest API更新文档字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用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更新文档字段

本文发布于:2023-11-28 10:08:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641970.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字段   文档   Firestore   Rest   API

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!