我尝试过使用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)在这个错误中,它提到了输入用户名和密码,我没有用户名和pasword.What,我必须输入,请帮助我。
发布于 2014-06-05 10:28:50
错误说:
throw Error("URL must be in the format mongodb://user:pass@host:port/dbnam")你试过加入协议了吗?(即:)
var db = mongo.db("mongodb://localhost:27017/mydb");发布于 2014-06-24 13:12:45
答案在于错误本身:
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();
});https://stackoverflow.com/questions/24057118
复制相似问题