MongoDB Mongoose agregat dua koleksi menggunakan pencarian

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"
        }
    }
])
amit.bhagat