【发布时间】:2020-09-12 17:44:06
【问题描述】:
我有一个使用 firebase 作为数据库的颤振项目。我正在尝试通过流获取文档名称列表,将其分成 10 个一组,以解决 firebase 中 .where() 函数的 10 个比较最大值,然后使用 .where() 发出批处理请求并合并它们。
我知道的问题是:
friends.length 不能用作循环中的数字,因为它是 future 类型
-
Firestore 查询返回无法添加到流列表中,原因我不明白(“无法将参数类型 'Query' 分配给参数类型 'Stream'。”)
.where() 期望 1 个位置参数,但我给它 3 个,尽管 Firestore 文档说我应该这样做
StreamGroup 欠精细
Stream<List<Memo>> get memos {
// create list of streams
List<Stream> streams = [];
// Get list of friend userids
var friends = Firestore.instance.collection("users").document(userid).collection("friends").snapshots().map(_snapshotToStringList);
// split friend userid list into chunks of 10
for (var i = 0; i < friends.length; i += 10) {
// query database for each chunk of 10 and add to stream list
streams.add(Firestore.instance.collection("memos").where("userid", "in", friends.sublist(i, i+10)));
}
// merge and return stream list
return StreamGroup.merge(streams);
}
感谢任何和所有建议
【问题讨论】:
标签: firebase flutter dart google-cloud-firestore stream