I have the following Express.js route
router.post('/', async (req, res) => {
try {
const {orderIDs} = req.body;
for (const orderID of orderIDs) {
const order = await Purchases.findById(orderID);
console.log(order)
const orderData = order.orderData;
// Update stock Levels
for (const item of orderData) {
const product = await Products.findOne({productCode: item.productCode});
await increaseQuantity(product.quantity, item.quantity, item.productCode);
}
// Update Purchases Table
await updateOrderStatusPurchases(orderID);
// Update TxnAudit Table
await updateStatusTXN_AUDIT(orderID);
}
res.status(200).json({ message: 'Pending orders received'});
} catch (error) {
logger.error(error);
res.status(500).json({ error: 'An error occurred while canceling orders' });
}
});
For some reason, whenever I try to retrieve a particular order from the database using the _id field results in a null value even though the document does exist in the database.
I have tried replacing await Purchases.findById(orderID) with await Purchases.findOne({"_id": orderID) with no luck.
I have also made sure that the Atlas User has the right permissions and that I am connecting to the correct mongodb instance.
Any help will be much appreciated.
Thanks in advance

