1
我有一个小问题。我试图执行一个简单的操作,但我一直得到相同的错误,我用尽了想法,并且我在互联网上找不到任何东西...连接到MongoDB的错误
导致错误的代码部分如下:
response.write(readDB(no)); // <= this line
response.end();
的readDB功能是在这里:
function readDB(gene){
console.log("test43");
MongoClient.connect(url, function(err, db) {
if(!err) {
console.log("We are connected");
console.log("test44");
var collection = db.collection('links');
var ans= collection.find({ generated: gene}, {original:1, _id:0}, function(err, gg){
console.log("test dat result:"+ans.original);
console.log("acces to:"+ans.original);
var rep
rep.writeHead(200, {"Content-Type": "text/html"});
rep.write("<html>");
rep.write("<head>");
rep.write("<title>Redirection</title>");
rep.write("<meta http-equiv=\"refresh\" content=\"5\"; URL=\""+ans.original+"\">");
rep.write("<script type=\"text/javascript\">window.location.href = \""+ans.original+"\"</script>");
rep.write("</head>");
rep.write("<body>Redirection...");
rep.write("</body>");
rep.write("</html>");
return rep;
})
}
if(err){
//console.log(err)
}
})};
我知道代码是不是很大,但仍... 消息“test43”在我的控制台显示,而我之后不断得到:
_http_outgoing.js:436
throw new TypeError('first argument must be a string or Buffer');
^
TypeError: first argument must be a string or Buffer
如果有人能告诉我我做错了什么,那会很棒!
谢谢!
我做了你的更正,它的工作原理!非常感谢你 !但是我现在有一个问题,执行返回: 'test42 test43 我们连接 test44 /home/ubuntu/workspace/UShort/node_modules/mongodb/lib/utils.js:98 process.nextTick(函数( ){throw err;}); ^ 类型错误:无法读取的不确定 ' 我猜它没有时间从数据库中检索数据并返回未定义的属性“原始” ... 你有这方面的任何解决方案? 再次感谢 – Barnabe
您可能很想追加到您的原始帖子,但我强烈建议您将新问题作为新问题发布,因为它最有可能吸引好的答案 –
是的,但我想它会更好地避免垃圾邮件,因为它不是非常重要...... – Barnabe