首页 > 解决方案 > 如何在 Firestore REST API runQuery 中对复合过滤器使用“或”操作

问题描述

我正在研究Firestore REST API runQuery

我想获得所有符合此条件的文件:

college == 'CUHK' OR college == 'HKU'

我在复合过滤器的操作中寻找"OR",不幸的是它不存在 (Firestore Official Documentation)

下面的查询有什么替代方法吗?(我想要但不存在的东西)

{
 "structuredQuery": {
  "from": [
   {
    "collectionId": "participants"
   }
  ],
  "where": {
   "compositeFilter": {
    "op": "OR", // <- what I want
    "filters": [
     {
      "fieldFilter": {
       "field": {
        "fieldPath": "college"
       },
       "op": "EQUAL",
       "value": {
        "stringValue": "CUHK"
       }
      }
     }, // OR
     {
      "fieldFilter": {
       "field": {
        "fieldPath": "college"
       },
       "op": "EQUAL",
       "value": {
        "stringValue": "HKU"
       }
      }
     }
    ]
   }
  }
 }
}

标签: firebasegoogle-cloud-firestore

解决方案


推荐阅读