Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 802
Mystique Avatar asked Apr 08 '18 23:04

Mystique


2 Answers

In your URL get rid of the Users.

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

like image 198
mfhasan2 Avatar answered Nov 11 '22 07:11

mfhasan2


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

like image 4
ooscarr Avatar answered Nov 11 '22 07:11

ooscarr