【发布时间】:2020-07-30 15:47:53
【问题描述】:
有谁知道为什么即使我已经在 MongoClient 构造函数中指定了 useUnifiedTopoology: true,我仍然会收到弃用警告?
提前谢谢你!
const mongodb = require('mongodb')
const MongoClient = mongodb.MongoClient
const connectionURL = 'connectionurl'
const databaseName = 'db'
const client = new MongoClient(connectionURL, { useNewUrlParser: true, useUnifiedTopology: true});
const insertHandler = async(data, collectionName) => {
await client.connect().then(async() => {
const collection = client.db(databaseName).collection(collectionName)
await collection.insertOne(data)
}).catch(error => {
console.log("Failed to insert:", error)
})
}
module.exports = {
insertHandler: insertHandler
}
我收到以下错误:
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.
【问题讨论】:
-
重启服务器再试一次
-
@kedarsedai 我已经停止 brew 并再次运行 mongoDB,但警告仍然存在。
标签: javascript reactjs database mongodb mongoose