簡體   English   中英

如何使用firebase firestore在子集合中搜索

[英]how to search in sub collection with firebase firestore

我想在 firebase 中的所有子集合中搜索

  return database
    .collection("students")
    .doc(/* usually I pass the student id here but want to get exams for all students */)
    .collection("exams")
    .where("score", ">=", 4)
    .get()

這有可能嗎? 更改我的數據庫並將考試存儲在一個集合中並將學生存儲在另一個集合中為時已晚。 很遺憾。 謝謝你

要在 Firestore 中跨多個集合進行搜索,您可以使用集合組查詢,它會查詢具有特定名稱的所有集合。

所以如果你想搜索所有學生的exams ,那就是:

database
    .collectionGroup("exams")
    .where("score", ">=", 4)
    .get()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM