I have an ordercollection in that i am storing the productDetails(it may contain array of objects) inside the productDetails i am having "products" object(this is also may be an array of objects, depending on the count of product which is ordered),so by using the inside"products" how to get that particular product details. Below is my order collection
{
"_id": ObjectId("59267748c1f80b17cd53a7bd"),
"updatedAt": ISODate("2017-05-25T06:33:41.827Z"),
"createdAt": ISODate("2017-05-25T06:18:48.264Z"),
"createdBy": "58ba6b8356a7bf05f613cda0",
"status": "shipment",
"productDetails": [
{
"_id": ObjectId("59267997c1f80b17cd53a7da"),
"productCatalogId": "592677eac1f80b17cd53a7be",
"quantity": 2,
"products": [
{
"productId": "5926791bc1f80b17cd53a7d1",
"_id": ObjectId("59267a94c1f80b17cd53a7ee")
},
{
"productId": "5926793bc1f80b17cd53a7d3",
"_id": ObjectId("59267aacc1f80b17cd53a7ef")
}
]
},
{
"_id": ObjectId("592679a1c1f80b17cd53a7db"),
"productCatalogId": "592678a5c1f80b17cd53a7c5",
"quantity": 1,
"products": [
{
"productId": "59267959c1f80b17cd53a7d5",
"_id": ObjectId("59267ac5c1f80b17cd53a7f0")
}
]
}
],
"__v": 0,
"OrderedFor": "58ba6b8356a7bf05f613cda0",
"billingId": ObjectId("592679d2c1f80b17cd53a7e2"),
"shipmentId": ObjectId("592679d2c1f80b17cd53a7e3")
}
and this my product collection
{
"_id": ObjectId("5926791bc1f80b17cd53a7d0"),
"updatedAt": ISODate("2017-05-25T06:32:52.590Z"),
"createdAt": ISODate("2017-05-25T06:26:35.529Z"),
"productCatalogId": "592677eac1f80b17cd53a7be",
"batch": "2017-05-25T06:26:35.510Z",
"createdBy": "58be7c914e5db93569289d27",
"products": [
{
"updatedAt": ISODate("2017-05-25T06:26:35.528Z"),
"createdAt": ISODate("2017-05-25T06:26:35.528Z"),
"serialno": "1016SAM0001",
"mfgdate": ISODate("2017-04-21T18:30:00.000Z"),
"mfgbatch": "1016",
"updatedBy": "58be7c914e5db93569289d27",
"_id": ObjectId("5926791bc1f80b17cd53a7d1"),
"status": "sold",
"addOnSerialnos": [
"1016RAK0001",
"1016SUJ0001"
]
}
],
"__v": 0
}
and my query is
exports.getInvoiceDetails = function(req, res) {
Order.findById(req.params.id)
.populate('shipmentId', 'shipmentId deliveryAddress deliveryContactPerson deliveryContact isCashonDelivery')
.populate('productDetails.productCatalogId', 'productDetails.productCatalogId language price.mrp warantydays name model version')
.populate('billingId', 'billingId billingAddress paymentMode grandTotalAmountPaid paymentStatus invoiceNumber invoiceItems')
.populate('productDetails.products.productId', 'serialno addOnSerianos')
.exec(function(error, order) {
if (error) return res.json(error);
return res.json(order);
});
};
via arun
No comments:
Post a Comment