Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query nested object in Firestore REST API

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!

like image 345
OmomSun Avatar asked Dec 04 '17 21:12

OmomSun


1 Answers

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.

like image 140
OmomSun Avatar answered Sep 20 '22 17:09

OmomSun