简体   繁体   中英

firebase - Firestore REST API starting query

Hello I am new to firestore and I'm trying to use the rest API to query from a collection called Users, find all users who have a field called about with the value test2

This is my POST request :

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

Body:

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

I get a response

{
    "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."
                    }
                ]
            }
        ]
    }
}

Can someone tell me what I am doing wrong ? Thanks a lot. I'm stuck and unable to proceed.

In your URL get rid of the Users.

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

Also, use stringValue instead of string value type. https://cloud.google.com/firestore/docs/reference/rest/v1beta1/Value

Just remember that you need to convert the url and take care with the version v1beta1 or v1, so in final form it will be like this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM