在Cloud Firestore中,如何获取所有尊重儿童某些条件的物品

时间:2018-11-06 22:22:49

标签: ios firebase google-cloud-firestore

我在Firebase的Cloud Firestore中具有此数据库结构:

@Repository
public interface PersonRepository extends JpaRepository<Person, Long>, QueryByExampleExecutor<Person> {
}

我想在Swift 4中检索所有拥有ID = 2的俱乐部。

此代码对我不起作用:

{
  "Club": [
    {
      "name": "club one",
      "address": "via Roma",
      "owners": [
        {
          "name": "Mario Rossi",
          "id": "1"
        },
        {
          "name": "Giorgio Verdi",
          "id": "2",
        }
      ]
    },
    {
      "name": "club two",
      "address": "via milano",
      "owners": [
        {
          "name": "Giorgio Verdi",
          "id": "2"
        }
      ]
    }
  ]
}

这是真正的数据库结构:

enter image description here

1 个答案:

答案 0 :(得分:1)

无法在您当前的结构中进行查询。您需要保留所有者ID的单独数组以允许此查询:

  "owner-ids": [ "1", "2" ],
  "owners": [
    {
      "name": "Mario Rossi",
      "id": "1"
    },
    {
      "name": "Giorgio Verdi",
      "id": "2",
    }
  ]

现在您可以在array-contains数组上使用owner-ids