简体   繁体   中英

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.

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

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