【发布时间】:2019-03-02 22:57:18
【问题描述】:
我正在尝试导出一个执行查询并返回包含该查询中的对象的数组的 firestore 函数。我正在尝试从文档的子集合中获取数据,并获取返回的文档对象数组以呈现给客户端。
我已经尝试了以下方法,但它不起作用(例如,对象返回空白)。我认为这与对承诺的不当处理有关,但我自己无法弄清楚。感谢您的帮助。
export const getEvents = (id) => {
let events = [];
firestore.collection('users')
.doc(id)
.collection('events')
.get()
.then((snapshot) => {
snapshot.forEach((doc) => events.push(doc));
});
return events;
};
【问题讨论】:
标签: arrays firebase google-cloud-firestore es6-promise