这是我使用插入文件到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