【问题标题】:I getting error while executing a web application using MongoDB使用 MongoDB 执行 Web 应用程序时出现错误
【发布时间】:2021-05-08 00:05:41
【问题描述】:

const mongoose = require('mongoose');

mongoose.Promise = global.Promise;

mongoose.connect('mongodb : //localhost:27017/taskmanager',{ useNewUrlParser: true ,useUnifiedTopology: true })
    .then(() => console.log('database connected'))
    .catch((error) => console.log(error));



module.exports = mongoose;

我收到 MongoParseError 错误:无效的连接字符串vs code

【问题讨论】:

    标签: javascript mongodb web-development-server


    【解决方案1】:
    mongoose.connect('mongodb://localhost/x', {
    useNewUrlParser: true,
    useUnifiedTopology: true,
    useFindAndModify: false,
    useCreateIndex: true  });
    

    是我在个人项目中使用的,在你的情况下,我认为导致错误的原因是 mongodb 和字符串的其余部分之间的空间。

    'mongodb : //localhost:27017/taskmanager'
    

    如猫鼬文档中所述:

    mongoose.connect('mongodb://username:password@host:port/database?options...', {useNewUrlParser: true});
    

    【讨论】:

    • 非常感谢,我已经挣扎了好几个小时了
    猜你喜欢
    • 2017-05-23
    • 2021-07-05
    • 1970-01-01
    • 2019-10-16
    • 2023-01-12
    • 2014-08-03
    • 2011-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多