我尝试使用下面提到的代码使用mongoskin节点模块连接mongo db
var mongo = require('mongoskin');
var db = mongo.db("localhost:27017/mydb");
db.bind('mycollection');
db.mycollection.find().toArray(function(err, items) {
console.log(items)
db.close();
});
我收到了下面提到的错误。
/usr/local/lib/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/url_parser.js:15
throw Error("URL must be in the format mongodb://user:pass@host:port/dbnam
^
Error: URL must be in the format mongodb://user:pass@host:port/dbname
at Error (<anonymous>)
at exports.parse (/usr/local/lib/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/connection/url_parser.js:15:11)
at Function.MongoClient.connect (/usr/local/lib/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/mongo_client.js:164:16)
at SkinClass.SkinDb._open (/usr/local/lib/node_modules/mongoskin/lib/db.js:36:25)
at SkinClass.open (/usr/local/lib/node_modules/mongoskin/lib/utils.js:162:14)
at SkinClass.SkinCollection._open (/usr/local/lib/node_modules/mongoskin/lib/collection.js:49:17)
at SkinClass.open (/usr/local/lib/node_modules/mongoskin/lib/utils.js:162:14)
at SkinClass.SkinCursor._open (/usr/local/lib/node_modules/mongoskin/lib/cursor.js:28:25)
at SkinClass.open (/usr/local/lib/node_modules/mongoskin/lib/utils.js:162:14)
at SkinClass.(anonymous function) [as toArray] (/usr/local/lib/node_modules/mongoskin/lib/utils.js:116:14)
在该错误中它提到输入用户名和密码。我没有用户名和密码。我必须输入的内容请帮助我。
答案 0 :(得分:0)
错误说:
throw Error("URL must be in the format mongodb://user:pass@host:port/dbnam")
您是否尝试过添加协议? (即:。)
var db = mongo.db("mongodb://localhost:27017/mydb");
答案 1 :(得分:0)
答案在于错误本身:
throw Error("URL must be in the format mongodb://user:pass@host:port/dbnam
^
Error: URL must be in the format mongodb://user:pass@host:port/dbname
如果您不理解,请按照以下说明行事:
var mongo = require('mongoskin');
var db = mongo.db("mongodb://localhost:27017/mydb");
db.bind('mycollection');
db.mycollection.find().toArray(function(err, items)
{
console.log(items)
db.close();
});