📜  mongo mongoose 加入聚合查找 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:04.605000             🧑  作者: Mango

代码示例1
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"
        }
    }
])