0

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;


Trajce12
  • 261
  • 2
  • 16
  • Does this answer your question? [Server Discovery And Monitoring engine is deprecated](https://stackoverflow.com/questions/57895175/server-discovery-and-monitoring-engine-is-deprecated) – Joe Mar 28 '20 at 02:23
  • Duplicate of https://stackoverflow.com/questions/57895175/server-discovery-and-monitoring-engine-is-deprecated – Joe Mar 28 '20 at 02:23

1 Answers1

0

The problem was that previous when i added the cmongoDB atlas cluster,i added ip to access to that server.And when you are on other ip it will not work.Adding option to mongoDB ATLAS for the both id or select 'ACCESS ALL' it will work.That was the reason for my error.

Trajce12
  • 261
  • 2
  • 16