【问题标题】:firebase - Firestore REST API starting queryfirebase - Firestore REST API 开始查询
【发布时间】:2018-09-18 07:36:41
【问题描述】:

您好,我是 firestore 新手,我正在尝试使用其余 API 从名为 Users 的集合中查询,查找所有拥有名为 about 且值为 test2 的字段的用户

这是我的 POST 请求:

https://firestore.googleapis.com/v1beta1/projects/{myprojectid}/databases/(默认)/documents/Users:runQuery

主体:

{
"structuredQuery": {
    "where" : {
        "fieldFilter" : { 
        "field": {"fieldPath": "about"}, 
        "op":"EQUAL", 
        "value": {"string": "test2"}
        }
    },
    "from": [{"collectionId": "Users"}]
    }
}

收到回复

{
    "error": {
        "code": 400,
        "message": "Invalid JSON payload received. Unknown name \"structured_query\" at 'document': Cannot find field.",
        "status": "INVALID_ARGUMENT",
        "details": [
            {
                "@type": "type.googleapis.com/google.rpc.BadRequest",
                "fieldViolations": [
                    {
                        "field": "document",
                        "description": "Invalid JSON payload received. Unknown name \"structured_query\" at 'document': Cannot find field."
                    }
                ]
            }
        ]
    }
}

谁能告诉我我做错了什么?非常感谢。我被卡住了,无法继续。

【问题讨论】:

    标签: rest google-cloud-firestore


    【解决方案1】:

    在您的 URL 中删除用户。

    https://firestore.googleapis.com/v1beta1/projects/{myprojectid}/databases/(默认)/documents:runQuery

    【讨论】:

    【解决方案2】:

    另外,使用stringValue 代替string 值类型。 https://cloud.google.com/firestore/docs/reference/rest/v1beta1/Value

    【讨论】:

      【解决方案3】:

      请记住,您需要转换 url 并注意版本 v1beta1 或 v1,因此最终形式将是这样的:

      https://firestore.googleapis.com/v1/projects/{myprojectid}/databases/%28default%29/documents:runQuery

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-05-13
        • 2020-06-14
        • 2018-05-08
        • 1970-01-01
        • 2018-03-25
        • 1970-01-01
        相关资源
        最近更新 更多