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