I am using mongoDB atlas cluster and express.js.I am having this error i've tried different solutions that i found on net but none of them works.
I am gettings this error on when i try through postman to send post request on the createProduct method
const MongoClient = require('mongodb').MongoClient;
const url = "mongodb+srv://xxx:xxx@cluster0-05vvl.mongodb.net/test?retryWrites=true&w=majority";
const createProduct = async (req, res, next) => {
const newProduct = {
name: req.body.name,
price: req.body.price
};
const client = new MongoClient(url);
try {
await client.connect();
const db = client.db();
const result = db.collection('products').insertOne(newProduct);
} catch (error) {
console.log(error);
return res.json({message: 'Could not store data.'});
};
client.close();
res.json(newProduct);
};
const getProducts = async (req, res, next) => {};
exports.createProduct = createProduct;
exports.getProducts = getProducts;