【发布时间】:2018-06-05 14:07:54
【问题描述】:
我认为这会更容易,但到目前为止还没有发生。我想遍历集合中的所有项目,而不是一次性下载每个项目。
假设我的收藏位于 ref /users 并且每个用户条目都有一个作为用户名的键,这样你最终会得到
/users/
jonsmith89: {}
janedoe_: {}
...
我没有orderBy() 的字段,因为这些对象中包含嵌入式集合,因此Pagination 的文档对我没有帮助。这就是我目前所拥有的
async IterateCollection(path, dataFunction, limit = 10) {
let collection = this.db.collection(path)
.limit(limit);
let current = collection;
let entries = 0;
do {
let snapshot = await current.get();
// Do something with snapshot.docs......
let last = snapshot.docs[snapshot.docs.length - 1];
current = collection.startAfter(last.data())
entries = snapshot.size;
} while (entries > 0);
}
我得到的是一个例外:
指定的游标值过多。指定的值必须与查询的 orderBy() 约束相匹配。
哪种是有意义的,但是我怎样才能按 id(key) 排序呢?我尝试了一个空白的orderBy() 以及orderBy('id'),即使没有 id 字段
【问题讨论】:
标签: javascript node.js firebase google-cloud-firestore