Answers for "mongo mongoose join aggregation lookup"

0

mongo mongoose join aggregation lookup

Pedido.aggregate([
    {
        $match: {} // add your search here
    },
    {
        $lookup: { // this is the alternative to the populate
            from: 'clientes',
            localField: 'cliente',
            foreignField: '_id',
            as: 'clientes'
        }
    },
    {
        $project: { // add all the fields you need from the collection, if you need to omit something from the query results, just don't mention it here
            id: 1,
            clientes: 1,
            date: { $dateToString: { format: "%d/%m/%Y", date: "$date" } } // this will return the date in the format "dd/MM/yyyy"
        }
    }
])
Posted by: Guest on February-25-2021

Code answers related to "mongo mongoose join aggregation lookup"

Code answers related to "Javascript"

Browse Popular Code Answers by Language