欢迎来到ZeroAO的博客

竹杖芒鞋轻胜马,谁怕?一蓑烟雨任平生。
扩大
缩小

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));

posted on 2020-05-28 11:24  Zeroao  阅读(2915)  评论(0编辑  收藏  举报

导航

Live2D