【问题标题】:why i am not able view the fetched data from the data base in console为什么我无法在控制台中查看从数据库中获取的数据
【发布时间】:2021-10-13 18:32:49
【问题描述】:

编写将从 Mongo 数据库中获取数据并在控制台中打印的代码。但它没有显示任何内容并停止

控制台 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.

代码

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);
});

【问题讨论】:

    标签: node.js mongodb


    【解决方案1】:

    试试猫鼬;

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

    或者

    mongoose.set('useNewUrlParser', true);
    

    另外请参考这个帖子:Server Discovery And Monitoring engine is deprecated

    【讨论】:

    • 你能告诉我把这条线放在哪里 mongoose.createConnection(uri, { useNewUrlParser: true });
    • 不做 Mongoos 有可能吗
    • 当然,您还有很多其他选项可以连接到 mongo。我建议您查看他们的文档以了解您的用例的 connect() 方法 docs.mongodb.com/manual/reference/method/connect 我猜它看起来像 MongoClient.connect(url, { useNewUrlParser: true });这里还有一些很好的输入stackoverflow.com/questions/50448272/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    相关资源
    最近更新 更多