11

I'm stuck with querying Firestore REST API. I can figure out how to filter by a regular key but I can't figure out how to query by nested object key.

Basically, in the browser client, I can do

firestore.collection("channels")
   .where("members.[memberID]", "==", true)
   .get()

However, when I try to do the same in the REST API, it said Invalid Argument. I was trying to do

{
 "structuredQuery": {
  "where": {
   "fieldFilter": {
    "field": {
     "fieldPath": "members.[memberID]"
    },
    "op": "EQUAL",
    "value": {
       booleanValue: "true"
    }
   }
  },
  "from": [
   {
    "collectionId": "channels"
   }
  ]
 }
}

but it gives me "Invalid Argument" error on fieldPath. Does anybody know how to query Firestore REST API based on nested object?

Thank you!

4
  • I have the same problem ... can't find a good answer to it. Commented Dec 5, 2017 at 2:26
  • What I may have to do is convert it to a string using JSONModel and then convert it back. Which seems a bit ugly. Commented Dec 5, 2017 at 2:36
  • Sorry for the dumb question but where do you pass this object with the structured query? I am passing it as request body and it does not work at all. Could someone share a whole example? Would be helpful. Commented Mar 25, 2018 at 14:00
  • 1
    @GeorgiArnaudov you need to pass the whole structuredQuery object in the request body, what I have above is the request body Commented Mar 26, 2018 at 14:46

1 Answer 1

12

I asked for Firebase support and they said special characters in fieldPath such as "-" in my case can be escaped using back tick or back slash. It is mentioned in the documentation. In my case, I'll need to do

members.`[memberID]`

I hope this is helpful for you guys.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.