Firestore REST API:查询对象的参数类型 [英] Firestore REST API: Query parameters type of object

查看:76
本文介绍了Firestore REST API:查询对象的参数类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找有关Google Firestore REST API的建议

I am looking for an advice regarding Google Firestore REST API

我正在尝试更新文档,但保留未更新的数据 ( https://cloud.google.com/firestore/docs/reference/rest/v1beta1/projects.databases.documents/patch )

I am trying to update the document but keep the data that are not updated (https://cloud.google.com/firestore/docs/reference/rest/v1beta1/projects.databases.documents/patch)

我在邮件"集合中有一个文档,该文档包含以下字段:时间戳记",邮件"和用户".

I have a document in "message" collection, the document contains following fields: "timestamp", "message" and "user".

如果我执行PATCH请求以更新消息"字段,则将删除时间戳"和用户"字段.

If I do the PATCH request to update the "message" field, then the "timestamp" and "user" fields are removed.

可以通过查询参数""updateMask"进行预防.该参数是对象的类型(DocumentMask). DocumentMask对象在文档中如下所示:

There is "Query Parameter" "updateMask" to preven this. The parameter is type of object (DocumentMask). The DocumentMask object looks like this in documentation:

{
  "fieldPaths": [
    string
  ],
}

没有示例显示这样的HTTP请求的样子.

There is no example how such a HTTP request should look like.

如果我要求构建这样的外观

If I build to request to look like this

PATCH https://firestore.googleapis.com/v1beta1/projects/{projectId}/databases/{databaseId}/documents/messages/someid?updateMask={"fieldPaths":["message"]}

请求正文包含所需的文档

The request body contains desired Document

此请求将在400上失败,名称为"updateMask"的参数无法绑定...

This request will fail on 400, that the parameter with name "updateMask" is unabled to bind...

如何使用PHP(Guzzle HTTP客户端)创建这样的请求?

How can I create such a request with PHP (Guzzle HTTP client)?

推荐答案

每个修补字段都需要作为单个参数包含在查询字符串中.
您可以将这种格式用于您的网址:

Each patched field needs to be included as an individual parameter in the query string.
You can use this format for your url :

https://firestore.googleapis.com/v1beta1/projects/<YOUR PROJECT>/databases/(default)/documents/messages/someid?updateMask.fieldPaths=message&updateMask.fieldPaths=<another_field_to_update>&updateMask.fieldPaths=<and_so_on>

从字段掩码中省略的字段将保持不变,无论它们是否包含在请求主体文档中.

Fields omitted from the field mask are unchanged, regardless if they are included in the request body Document.

您可以使用Google REST API资源管理器从我们的用户友好界面生成带有查询参数和正文的预定义URL:

You can use the Google REST API explorer to generate pre-defined URL with Query Parameters and Body from us user friendly interface:

https://developers.google.com/apis-explorer/

这篇关于Firestore REST API:查询对象的参数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆