【发布时间】: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);
});
【问题讨论】: