在Firestore REST API中查询嵌套对象

时间:2017-12-04 21:42:03

标签: firebase firebase-realtime-database google-cloud-firestore

我一直坚持查询Firestore REST API。我可以弄清楚如何通过常规密钥进行过滤,但我无法弄清楚如何通过嵌套对象密钥进行查询。

基本上,在浏览器客户端,我可以做到

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

但是,当我尝试在REST API中执行相同操作时,它表示无效参数。我试图做

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

但它给了我"无效的论据" fieldPath上的错误。有人知道如何基于嵌套对象查询Firestore REST API吗?

谢谢!

1 个答案:

答案 0 :(得分:6)

我要求Firebase支持,他们说fieldPath中的特殊字符,例如“ - ”,在我的情况下,可以使用后退或反斜杠进行转义。提到in the documentation。就我而言,我需要做

members.`[memberID]`

我希望这对你们有帮助。