No Preview

iiZiro big-pp

Posted on 10 September 2021

Flipcart clone issue. Cannot read property '_id' of null

No Preview

when i login the server crashing and send me this error i tried to fix it by my self but I couldn't so pls if any one can help text me on instagram: iiziro_sama

exports.getCartItems = (req, res) => { Cart.findOne({ user: req.user._id }) .populate('cartItems.product', '_id name price productPictures') .exec((error, cart) => { if (error) return res.status(400).json({ error }); if (cart) { let cartItems = {}; cart.cartItems.forEach((item, index) => { cartItems[item.product._id.toString()] = { _id: item.product._id.toString(), name: item.product.name, img: item.product.productPictures[0].img, price: item.product.price, qty: item.quantity, } }) res.status(200).json({ cartItems }) } }) }

CONSOLE ERROR

TypeError: Cannot read property '_id' of null at C:\Users\iiZiro009\Documents\mern-ecommerce\mern-back-end\src\controller\cart.js:93:44 at CoreDocumentArray.forEach () at C:\Users\iiZiro009\Documents\mern-ecommerce\mern-back-end\src\controller\cart.js:92:32 at C:\Users\iiZiro009\Documents\mern-ecommerce\mern-back-end\node_modules\mongoose\lib\model.js:4870:16 at C:\Users\iiZiro009\Documents\mern-ecommerce\mern-back-end\node_modules\mongoose\lib\helpers\promiseOr at C:\Users\iiZiro009\Documents\mern-ecommerce\mern-back-end\node_modules\mongoose\lib\model.js:4893:21 at C:\Users\iiZiro009\Documents\mern-ecommerce\mern-back-end\node_modules\mongoose\lib\query.js:4400:11 at C:\Users\iiZiro009\Documents\mern-ecommerce\mern-back-end\node_modules\kareem\index.js:136:16 at processTicksAndRejections (internal/process/task_queues.js:77:11) Emitted 'error' event on Function instance at: at C:\Users\iiZiro009\Documents\mern-ecommerce\mern-back-end\node_modules\mongoose\lib\model.js:4872:13 at C:\Users\iiZiro009\Documents\mern-ecommerce\mern-back-end\node_modules\mongoose\lib\helpers\promiseOr [... lines matching original stack trace ...] at processTicksAndRejections (internal/process/task_queues.js:77:11)

0

49

0

No Preview

iiZiro big-pp

Explore more similar Post

1 Comments

iiZiro big-pp

10 September 2021

i find the problem, you gonna have this problem when you delete a product but someone have it in his cart

0
REPLY

Rizwan Khan

30 September 2021

Thank you for the update we will look over this issue

REPLY