【发布时间】:2021-07-04 03:34:11
【问题描述】:
我在获取用户时遇到问题,他们的电子邮件在其他用户的数组“SeniorList”中。当我有一个用户发送电子邮件时,它会打印我的空数组
_seniorList
我是 Firebase 新手,所以每条建议都很重要。
这是 Firestore 数据库结构:
我试过的代码:
Future<List<String>> getSeniorList() async {
var _currentUser = FirebaseAuth.instance.currentUser;
List<String> list;
DocumentSnapshot data = await FirebaseFirestore.instance
.collection('users')
.doc(_currentUser!.uid)
.get();
list = List.from(data['SeniorList']);
return list;
}
Future<void> printSeniorNameList() async {
final List<String> _seniorList = await getSeniorList();
print(_seniorList);
final QuerySnapshot result = await FirebaseFirestore.instance
.collection('users')
.where('email', arrayContainsAny: _seniorList)
.get();
final List<DocumentSnapshot> documents = result.docs;
print(documents);
}
PS。如果你能告诉我如何以正确的方式粘贴图片,我将不胜感激!
【问题讨论】:
-
列表为空,因为您的文档中没有任何名为 SeniorList 的属性
-
您是否尝试过使用 whereIn 而不是 arrayContainsAny?从我的角度来看,它更有意义
-
whereIn 没有改变;
-
图片的添加方式与链接相同,但开头带有感叹号:
。请参考Markdown help。您能否也更新您的答案,添加对解决您问题的确切更改的描述?这将有助于使答案更加直观。
标签: firebase flutter google-cloud-firestore