I am trying to fetch 6 month of my brand transaction data from documents using Node JS as my backend. After 1 minutes its showing network error. Am using AWS as my web app host.
In postman its taking 3min to fetch data but in server its giving network error after just 1 min.
here is my code,
let brandData = await item.aggregate(
[
{
$match: {
$expr: {
$cond:{
if:brand_id,
then:{$eq: ["$brand_id", brand_id]},
else:’’
}
}
}
},
{
$sort: {
item: 1,
}
},
{
$project: {
_id: 0,
item_id: 1,
uom_id: 1,
item: 1,
brand_id: 1
}
},
{
$lookup:
{
from: "t_100_uoms",
let: {
"uom_id": "$uom_id"
},
pipeline: [
{
$match: {
$expr: {
$eq: ["$$uom_id", "$uom_id"]
}
}
}, {
$project: {
caption: 1,
}
}
], as: 'uom'
}
},
{
$addFields: {
caption: { $first: "$uom.caption" }
}
},
{
$lookup:
{
from: "t_100_brands",
let: {
"brand_id": "$brand_id"
},
pipeline: [
{
$match: {
$expr: {
$eq: ["$$brand_id", "$brand_id"]
}
}
}, {
$project: {
brand: 1,
}
}
], as: 'brand'
}
},
{
$addFields: {
brand: "$brand.brand"
}
},
{
$lookup: {
from: 't_900_sales',
let: {
"item_id": "$item_id"
},
pipeline: [
{ $unwind: "$invoice_details" },
{ $unwind: "$invoice_item_details" },
{
$match: {
$expr: {
$and: [
{ $eq: ["$invoice_item_details.item_id", "$$item_id"] },
{ $eq: ["$invoice_item_details.invoice_no", "$invoice_details.invoice_no"] },
{ $gte: ["$invoice_details.invoice_date", fromDate] },
{ $lte: ["$invoice_details.invoice_date", toDate] },
]
}
}
},
{
$project: {
_id: 0,
netValue: { $sum: { $toDouble: "$invoice_item_details.net_value" } },
qty: { $sum: { $toDouble: "$invoice_item_details.now_dispatch_qty" } },
itemId: "$invoice_item_details.item_id",
}
},
{
$group: {
_id: "$itemId",
totalNetValue: { $sum: "$netValue" },
qty: { $sum: "$qty" },
}
}
], as: "sales"
}
},
{
$addFields: {
totalNetValue: {
$round: [{ $ifNull: [{ $first: "$sales.totalNetValue" }, 0] }, 2]
},
qty: {
$ifNull: [{ $first: "$sales.qty" }, 0]
},
brand: { $first: "$brand" },
}
},
{
$unset: ["sales", "uom"]
},
{
$group: {
_id:"$brand_id",
brand: {$first:"$brand"},
// caption:{$first:"$caption"},
totalNetValue:{$sum:"$totalNetValue"} ,
qty:{$sum:"$qty"}
}
},
],
)