node.js连接mongodb失败问题(node:5808) UnhandledPromiseRejectionWarning: MongoParseError: Invalid connectio n string
连接
const mongoose = require('mongoose')
const Schema = mongoose.Schema
//连接
mongoose.connect('mongoose://localhost:27017/test', {
useNewUrlParser: true,
useUnifiedTopology: true
})
报错

改为
var url = process.env.DATABASE_URL || "mongodb://localhost:27017/test"; mongoose.connect(url, { useNewUrlParser: true }) .then(() => console.log("Connection Successful")) .catch(err => console.log(err));
浙公网安备 33010602011771号