所以我有以下代码:
app.get('/all', (req,res) => {
User.aggregate([{
$lookup: {
from: "boughtitems", // collection name in db
localField: "username",
foreignField: "username",
as: "boughtitems"
}
}]).then((users) => {
console.log(users);
});
});
这是我得到的: enter image description here
如何访问boughtitems
?就像我想这样做:
.then((users) => {
res.render('index', {users});
然后在文件中执行以下操作:
{{#each users}}
//how to display boughtitems data with "this" ?
{{/each}}