[英]How to get document with certain fields from firebase to flutter?
I need a flutter query for getting data from firebase;我需要一个 flutter 查询来从 firebase 获取数据;
The query should go to User collection and search every document with UserType = 1 field.查询应 go 到 User 集合并搜索 UserType = 1 字段的每个文档。 There is a "classes" collection in each document and each of "classes" have other documents such as "math", "music" etc. I need to get the document with the field classCode == myInput
每个文档中有一个“类”集合,每个“类”都有其他文档,例如“数学”、“音乐”等。我需要使用字段 classCode == myInput 获取文档
QuerySnapshot query1 = await _fireStore.collection("Users").where(["userType"], isEqualTo: 1).get();
I don't know how to move from here.我不知道如何离开这里。
You have two main options for implement this.您有两个主要选项来实现这一点。
The first is pretty close to how you describe in your question:第一个非常接近您在问题中的描述:
classes
subcollection for the classCode
.classes
子集合中搜索classCode
。 The second approach makes use of a collection group query to:第二种方法利用集合组查询来:
classes
docs (across all the subcollections) with the searched user type.classes
文档(跨所有子集合)。 The best approach depends on mostly on what results you need.最好的方法主要取决于您需要什么结果。 If you results are user documents, the first approach is usually pretty easy.
如果您的结果是用户文档,第一种方法通常很简单。 If the results are
classes
then I'd definitely try the second approach first.如果结果是
classes
,那么我肯定会先尝试第二种方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.