const orders = await db1.db.collection("order_all").find({
progress_status_kd: { $in: [32, 33] },
ps_screen_preparing_n_packaging_permission: true,
$expr: {
$lte: [
"$progress_status_kd_updated_at",
// "2025-05-07 13:59:40" from this condition bellow it should return date format like this, it works if I put hardcoded date but not from this $cond
{
$cond: [
{ $eq : ["$progress_status_kd", 33] },
moment().subtract("$kdsConfig.ps_screen_preparing_time", 'hours'),
moment().subtract("$kdsConfig.ps_screen_packaging_time", 'minutes')
]
}
],
}
}).toArray();
I want to subtract a dynamic value based on a condition. If progress_status_kd === 33, it should subtract with the ps_screen_preparing_time value from kdsConfig. How can I achieve this, as currently it is not working correctly as expected?
Here is my MongoDB data:
{
"_id": ObjectId("681a0a555133c90d813dac22"),
"kdsConfig": {
"ps_screen_packaging_time" : 10,
"ps_screen_preparing_time" : 10
},
"progress_status_kd": 33,
"progress_status_kd_updated_at": "2025-05-07 14:00:00",
"ps_screen_preparing_n_packaging_permission": true
}