【发布时间】:2019-03-27 10:16:42
【问题描述】:
我正在尝试找出一种方法来获取文档集合及其子集合数据。
例如,我的树是……
-locations
-{locationId}
-historic
-april
-airTemp: 12.4
-displayOrder: 4
-august
-airTemp: 14.5
-displayOrder: 9
-december
-airTemp: 13.5
-displayOrder: 12
etc..
...其中locationId 是一个文档,historic 是其中包含每月文档的子集合。
我知道如何获取顶级集合项并将其存储到数组中,但我也想将它们的子集合数据(即 jan、feb 等)添加到每个文档中。
var locations = []
let ref = db.collection('locations')
db.collection('locations').get()
.then(snapshot => {
snapshot.forEach(doc => {
let location = doc.data()
location.id = doc.id
location.name = doc.name
// get the historic subcollection data here
})
})
如何从每个对象中获取组合数据(集合和子集合),然后将其推送到数组中?
赏金结构错误 每个月都应该是它自己的对象
【问题讨论】:
-
“我也想将他们的子集合数据(即 1 月、2 月)添加到每个文档中”是什么意思。您的意思是在数据库中还是在读取数据库时在您的前端?
-
@RenaudTarnec 在前端读取数据库
标签: firebase promise async-await google-cloud-firestore