Order.aggregate( [ { $unwind: "$products" }, { $unwind: "$products.product" }, { $sort: { orderDate: 1 } } ], function (err, result) { Order.populate( result, [ { path: "products.product", model: "Product" }, { path: "address", model: "Address" } ], function (err, results) { let sellerItemsToShip = results.filter( order => order.products.product.seller == userId && order.products.orderState.shipped == false ); if (err) res.status(400).json({ message: "Couldn't get orders", err }); return res.status(200).json({ ordersToShip: sellerItemsToShip }); } ); } );
const article = await Article.aggregate([ { $match }, { $unwind: '$tag' },
const article = await Article.aggregate([ { $match: { state: 1, publish: 1 } },
Order.aggregate( [ { $unwind: "$products" }, { $unwind: "$products.product" }, { $sort: { orderDate: -1 } } ], function (err, result) { Order.populate( result, [ { path: "products.product", model: "Product" }, { path: "address", model: "Address" } ], function (err, results) { let sellerShippedOrders = results.filter( order => order.products.product.seller == userId && order.products.orderState.shipped == true ); if (err) res.status(400).json({ message: "Couldn't get orders", err }); return res.status(200).json({ shippedOrders: sellerShippedOrders }); } ); } );