如何访问文件中的$ lookup表对象

时间:2018-10-10 15:04:22

标签: node.js mongodb mongoose

所以我有以下代码:

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}}

0 个答案:

没有答案