Firestore REST API starting query

2019-06-24 21:24发布

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.

1条回答
贪生不怕死
2楼-- · 2019-06-24 21:34

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"}]
    }
}
查看更多
登录 后发表回答