【问题标题】:Loopback mongodb connector no hostname or hostnames provided in connection stringLoopback mongodb 连接器在连接字符串中未提供主机名或主机名
【发布时间】:2015-11-13 23:54:18
【问题描述】:

当我启动环回服务器时,我收到了这个错误。代码中的一切看起来都很完美。我正在传递主机名、数据库名称、用户名、密码和端口。

 /var/www/investickations_web/node_modules/loopback-connector-mongodb/node_modules/mongodb/lib/url_parser.js:24
        throw new Error('no hostname or hostnames provided in connection string');
    ^

Error: no hostname or hostnames provided in connection string
    at module.exports (/var/www/investickations_web/node_modules/loopback-connector-mongodb/node_modules/mongodb/lib/url_parser.js:24:11)
    at connect (/var/www/investickations_web/node_modules/loopback-connector-mongodb/node_modules/mongodb/lib/mongo_client.js:125:16)
    at Function.MongoClient.connect (/var/www/investickations_web/node_modules/loopback-connector-mongodb/node_modules/mongodb/lib/mongo_client.js:109:3)
    at MongoDB.connect (/var/www/investickations_web/node_modules/loopback-connector-mongodb/lib/mongodb.js:113:25)
    at Object.initializeDataSource [as initialize] (/var/www/investickations_web/node_modules/loopback-connector-mongodb/lib/mongodb.js:70:26)
    at DataSource.setup (/var/www/investickations_web/node_modules/loopback-datasource-juggler/lib/datasource.js:332:17)
    at new DataSource (/var/www/investickations_web/node_modules/loopback-datasource-juggler/lib/datasource.js:109:8)
    at Registry.createDataSource (/var/www/investickations_web/node_modules/loopback/lib/registry.js:349:12)
    at dataSourcesFromConfig (/var/www/investickations_web/node_modules/loopback/lib/application.js:415:19)
    at EventEmitter.app.dataSource (/var/www/investickations_web/node_modules/loopback/lib/application.js:222:12)

【问题讨论】:

    标签: loopbackjs strongloop


    【解决方案1】:

    在 Loopback-MongoDB-Connector 的 url_parser.js 中发现了一个 bug。如果您的密码字符串中有@,则它无法解析和构建 MongoDB 连接字符串。

    所以要么自己准备连接字符串并将其作为数据源 JSON 中的“url”字段传递,要么更改 MongoDB 密码,使其不包含 @ 字符。

    【讨论】:

      【解决方案2】:

      这是一个连接到 mongo 的示例连接字符串。正如achintverma所说,不要在密码中使用@。

      "mongoDS": {
          "url": "mongodb://paanoop:*password*@ds035683.mongolab.com:1234/fsbs",
          "database": "",
          "password": "*password*",
          "name": "your data source",
          "user": "username",
          "connector": "mongodb"
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-12-04
        • 1970-01-01
        • 2019-06-22
        • 1970-01-01
        • 2012-06-21
        • 1970-01-01
        • 2017-11-07
        • 1970-01-01
        相关资源
        最近更新 更多