這是我使用插入文件到mongodb的第th個代碼。與nodejs的mongodb
var client = new Db('test', new Server("127.0.0.1", 27017, {}), {w: 1}),
test = function (err, collection) {
collection.insert({a:2}, function(err, docs) {
collection.count(function(err, count) {
test.assertEquals(1, count);
});
// Locate all the entries using find
collection.find().toArray(function(err, results) {
test.assertEquals(1, results.length);
test.assertTrue(results[0].a === 2);
// Let's close the db
client.close();
});
});
};
client.open(function(err, p_client) {
client.collection('test_insert', test);
});
,但在運行我得到錯誤
xports,要求,模塊,__filename,__dirname){VAR的客戶=新的DB( '測試', ^ 的ReferenceError:DB是沒有定義 在。對象(C:\用戶\基本節點\ cheerio \ mongonode.js:1:81
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)
你能建議我該如何解決這個問題
在此先感謝
問題非常明確。 'Db'變量沒有定義。如果你想得到一個正確的答案,你必須在最初聲明你的Db(可能是服務器)對象的地方發佈代碼。 – 2013-03-11 07:05:35
你在哪裏定義Db。也許你錯過了導入有Db的模塊。 – user568109 2013-03-11 11:39:10
我忘了導入mongodb模塊。知道它工作正常。感謝您的回覆 – Ramesh 2013-03-11 12:23:19