我的firebase项目具有以下firestore集合。
{
name: "ninja250r",
maker: "kawasaki",
reserves: [
0 : [
id: "1",
start_datetime: "2019-09-11 12:00:00",
end_datetime: "2019-09-11 17:00:00",
]
1 : [
id: "2",
start_datetime: "2019-09-11 12:00:00",
end_datetime: "2019-09-11 17:00:00",
]
]
}
routes / bikes.js
router.get('/', function(req, res, next) {
db.collection('bikes').get()
.then(snapshot => {
var bikes = new Array();
snapshot.forEach(doc => {
bikes.push({
id: doc.id,
bikes: doc.data(),
})
})
res.render('bikes', {
title: 'all bikes',
bike: bikes
});
console.log(bikes);
})
.catch(err => {
next(err);
});
});
view / bikes.pug
ul
each item in bike
li id:#{item.id}
br
| name:#{item.bikes.name}
br
| reserves:#{item.bikes.reserves}
然后运行
$firebase serve
日志显示如下
> [ { id: '1',
> bikes: { name: 'ninja250r', reserves: [Array], maker: 'kawasaki' } },
下面显示的网站。
id:1
name:ninja250r
reserves:[object Object],[object Object]
我想显示保留数组(id,start_datetime,end_datetime),但是我不知道该怎么办。 如何显示储备金?
我尝试了另一种使用子集合的方法,但是无法同时获得集合中的子集合。
参考链接 Firebase Firestore Get Subcollections for each document in a collection