neutralinojs / neutralinojs-minimal

The simplest template for a Neutralinojs app
MIT License
50 stars 13 forks source link

Mongodb $lookup give [] #21

Open BLACKJACKDEVELOPER opened 1 year ago

BLACKJACKDEVELOPER commented 1 year ago

Here is my code that attempt to use $lookup.I think it's correct but "UserDetail" give me a [] to all data


async get(req,res) {
        try {
            const { query:{ room } } = req
            const data = await msgs.aggregate([
            {
                $lookup: {
                    from: "users", localField: "user_id", foreignField: "id", as: "UserDetail"
            }
        }
    ]);
            console.log(data)
            return res.json({
                data,
                pass:true
            })
        }catch(e) {
            console.log(e)
            return res.json({
                pass:false,
                msg:e.message
            })
        }
    }
dhruvinjs commented 1 month ago

hey so am new here so can u assign me this issue here

dhruvinjs commented 1 month ago

async get(req,res) { try { const { query:{ room } } = req const data = await msgs.aggregate([ { $lookup: { from: "users", localField: "user_id", foreignField: "_id", as: "UserDetail" } } ]); console.log(data) return res.json({ data, pass:true }) }catch(e) { console.log(e) return res.json({ pass:false, msg:e.message }) } } hey i think there is a typo error in your code assuming if u want to match the id which I think is ObjectId so just have to change "id" to "_id"