firebase - Firestore REST API 开始查询

问题描述 投票:0回答:3

您好,我是 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
3个回答
14
投票

在您的 URL 中删除用户。

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


4
投票

此外,使用

stringValue
而不是
string
值类型。 https://cloud.google.com/firestore/docs/reference/rest/v1beta1/Value


0
投票

请记住,您需要转换 url 并注意版本 v1beta1 或 v1,因此最终形式将如下所示:

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

© www.soinside.com 2019 - 2024. All rights reserved.