Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore REST API starting query

I am struggling with Firestore REST API. Database have a collection with Users. Every user is separate document. I need to get all users with, for example, category equal 1. Here is my attempt (request body):

{
      "structuredQuery": {
            "where" : {
                "fieldFilter" : { 
                      "field": { "fieldPath" : "category" } , 
                                 "op":"EQUAL", 
                                 "value": { "integerValue" : 1 }
                                }
                      }

      }

    }

and response error:

"error": {
  "code": 400,
  "message": "kind is required for filter: category",
  "status": "INVALID_ARGUMENT"
}

I have totaly no idea, how "field" inside "fieldFilter" should looks like. Thanks in advance.

like image 430
Rajju Avatar asked Nov 09 '17 19:11

Rajju


1 Answers

I believe if you include the "from" property of the structured query, this will work. If the collection you're querying from is called "users" it would look like this, based on what you posted above:

{
    "structuredQuery": {
        "where" : {
            "fieldFilter" : { 
                "field": {"fieldPath": "category"}, 
                "op":"EQUAL", 
                "value": {"integerValue": 1}
            }
        },
        "from": [{"collectionId": "users"}]
    }
}
like image 112
Veatch Avatar answered Oct 21 '22 02:10

Veatch