Foreign collection doesn't seem to be appearing in aggregated data Foreign collection doesn't seem to be appearing in aggregated data express express

Foreign collection doesn't seem to be appearing in aggregated data


You are writing 'User' as collection name, please check saved collection name in MongoDB. It should be saved as 'users' collection. So, you have to write 'users' in lookup like below code:

router.get('/forum', async (req,res)=>res.render('forum', {        newPost: await Createpost.aggregate([    {        $lookup: {             from: "users",              localField: "postUsername",              foreignField: "username",              as: "postUser"        }    },    {        $sort: {date: -1}    }      ])}));