使用在windows上运行的node.js代码connectiong mongodb的以下代码片段:
var mongo = require("mongodb");
var host = "127.0.0.1";
var port = mongo.Connection.DEFAULT_PORT;
var db = new mongo.db("nodetest", new mongo.Server(host, port, {}));
db.open(function(error){
console.log("connected" + host + ":" + port);
});
各自的错误是:
C:\nodetest\mongo.js:5
var db = new mongo.db("nodetest", new mongo.Server(host, port, {}));
^
TypeError: undefined is not a function
at Object.<anonymous> (C:\nodetest\mongo.js:5:10)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.runMain (module.js:492:10)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
C:\nodetest>
相同的代码适用于ubuntu。有什么指针吗?
答案 0 :(得分:0)
谢谢robertklep。问题在于“Db”。但是“db”与Ubuntu一起工作正常。