I have tried adding document using mongoose. The following code in productController.js, returns the following response.
Code:
exports.createProduct = async (req, res, next) => {
try {
console.log("Request Body:", req.body); // Log the request body for debugging
const product = await Product.create(req.body);
res.status(201).json({
success: true,
product,
});
} catch (error) {
console.error("Error creating product:", error);
res.status(400).json({
success: false,
message: error.message,
});
}
};
Response:
Request Body: {
name: ‘Vaseline petrolatum Jelly’,
description: ‘Simple product.’,
price: 100,
rating: 3,
category: ‘Health’,
images: { public_id: ‘sample public id’, url: ‘sample url’ }
}
but I cannot seem to find it in compass.
I have checked the DB_URL etc. and checked to see if there are any faults but there do not seem to be any.
ahmed khan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.