'Cannot read findById of underfined in Mongoose
When I call the function, I getting TypeError: Cannot read property 'findById' of undefined
Any help will be really appreciated
Here is the code.
exports.getProductSellingPrice = async (productId) => {
const product = await Product.findById(productId).select("sellingPrice -_id");
return Number(product.sellingPrice);
};
Using the intellisense it can show that the Product is imported well 
However, when I run the code I am getting the error
TypeError: Cannot read property 'findById' of undefined
31 |
32 | exports.getProductSellingPrice = async (productId) => {
> 33 | const product = await Product.findById(productId).select("sellingPrice -_id");
| ^
34 | return Number(product.sellingPrice);
35 | };
36 |
at Object.findById [as getProductSellingPrice] (src/database/services/user.js:33:33)
at model.getProductSellingPrice [as addProductsToCart] (src/database/models/user.js:48:43)
at Object.addProductsToCart (tests/models/user.test.js:94:24)
at runMicrotasks (<anonymous>)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
