选项远程 mongodb 的键值对不完整 [英] Incomplete key value pair for option remote mongodb

查看:66
本文介绍了选项远程 mongodb 的键值对不完整的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将我的本地节点 mongoDB 应用程序部署到 Heroku.在我的本地机器上一切正常,没有错误.

I'm trying to deploy my local node mongoDB app to Heroku. Everything is working fine on my local machine, no errors.

我尝试做的第一件事是连接到 mlab 上的数据库.它看起来非常简单,但我收到此错误:

First thing I'm trying to do is to connect to a database on mlab. It seen very straight forward but I get this error:

err { MongoParseError: Incomplete key value pair for option
  name: 'MongoParseError',
  message: 'Incomplete key value pair for option',
  [Symbol(mongoErrorContextSymbol)]: {} }

我的代码如下所示:

    var mongoose = require('mongoose');

    const options = {
            useNewUrlParser: true
          };

    mongoose.connect("mongodb://username:password@xxxxx.mlab.com:39251/nameodDB",options).then(
   ()=>{
      console.log("connected to mongoDB")},
   (err)=>{
       console.log("err",err);
 });

推荐答案

MongoDB 密码如果包含@"等特殊字符,则需要进行 URLEncoded突出显示主机的开始

MongoDB password needs to be URLEncoded if it consists of special characters like "@" which highlights the start of the host

这篇关于选项远程 mongodb 的键值对不完整的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆