数据库遇到的问题集合
Opened this issue · 0 comments
Shenchuanhuan commented
mongoose
连接报错:UnhandledPromiseRejectionWarning: Error: Invalid schema, expected "mongodb" or "mongodb+srv"
自己写的连接是:
const mongoose = require('mongoose');
mongoose.connect("localhost/testDatabase", function(err) {
if (err) {
console.log(err, '连接失败');
} else {
console.log('连接成功');
}
});
正确的写法是:
const mongoose = require('mongoose');
mongoose.connect("mongodb://localhost/testDatabase", function(err) {
if (err) {
console.log(err, '连接失败');
} else {
console.log('连接成功');
}
});
//在url的前面添加mongodb://