当我启动环回服务器时,我收到此错误。代码中的一切看起来都很完美。我传递主机名,数据库名称,用户名,密码和端口。
/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)
答案 0 :(得分:3)
发现Loopback-MongoDB-Connector的url_parser.js中存在错误。如果密码字符串中包含@,则无法解析并构建MongoDB连接字符串。
请自行准备好连接字符串并将其作为' url'数据源JSON中的字段或更改您的MongoDB密码,因此它不包含@字符。
答案 1 :(得分:1)
以下是连接到mongo的示例连接字符串。正如achintverma所说,不要在密码中使用@。
"mongoDS": {
"url": "mongodb://paanoop:*password*@ds035683.mongolab.com:1234/fsbs",
"database": "",
"password": "*password*",
"name": "your data source",
"user": "username",
"connector": "mongodb"
}