0

Written the code which will fetch the data from the Mongo db and print in the console .But it is not displaying me any thing and getting stoped

Console O/P -

(node:85991) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

Code

const MongoClient = require ('mongodb');
const url = 'mongodb://10.142.206.22:27017/';
const databasename = 'snapp_transactions';  // Database name
MongoClient.connect (url).then ((client) => {

  const connect = client.db (databasename);

  // Connect to collection
  const collection = connect
    .collection ('redemptions');

  collection.find ({}).toArray ().then ((ans) => {
    console.log (ans);
  });
}).catch ((err) => {

  // Printing the error message
  console.log (err.Message);
});
johan jk
  • 39
  • 1
  • 6

1 Answers1

0

Try with mongoose;

mongoose.createConnection(uri, { useNewUrlParser: true });

Or

mongoose.set('useNewUrlParser', true);

Also please refer to this thread: Server Discovery And Monitoring engine is deprecated

Jacopo
  • 143
  • 1
  • 1
  • 10
  • can you tell where to keep this line mongoose.createConnection(uri, { useNewUrlParser: true }); – johan jk Aug 10 '21 at 07:40
  • is that possible with out doing Mongoos – johan jk Aug 10 '21 at 07:41
  • Sure, you have a lot of other options to connect to mongo. I recommend you have a look at their documentation for the connect() method https://docs.mongodb.com/manual/reference/method/connect/ for your use case I guess it would look like MongoClient.connect(url, { useNewUrlParser: true }); Also a few good inputs are here https://stackoverflow.com/questions/50448272/avoid-current-url-string-parser-is-deprecated-warning-by-setting-usenewurlpars – Jacopo Aug 10 '21 at 09:32