【发布时间】:2020-04-14 01:44:40
【问题描述】:
我正在使用猫鼬。 5.8.2 并遵循该人在 v3.5 上运行 mongoose 的教程。我知道有一些变化,比如 useNewUrlParser 已被弃用,而是我们使用 useUnifiedTopology 但问题是每当我使用 useUnifiedTopology 时,我都会收到它已被弃用的错误。请看下面,让我知道我做错了什么
const mongoose = require('mongoose')
mongoose.createConnection('mongodb://127.0.0.1:27017/task-manager-api', {
useUnifiedToplogy: true,
useCreateIndex: true
});
const User = mongoose.model('User', {
name: {
type: String
},
age: {
type: Number
}
})
const me = new User({
name: 'Lallan',
age: '27'
})
me.save().then(() => {
console.log('Done')
}).catch((error) => {
console.log('error', error)
})
以下是错误,我无法将 mongoose 与 mongodb 连接
the options [useUnifiedToplogy] is not supported
(node:6573) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
(node:6573) 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.
mongoose 和 mongodb 连接应该怎么做?
【问题讨论】: