이것은 th 코드입니다. mongodb에 문서를 삽입하는 중입니다.mongodb with nodejs
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 : \ 사용자 기본 노드를 \ \ 안녕 \ 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 (그리고 아마도 서버) 객체를 선언 할 곳에서 코드를 게시해야합니다. –
Db 정의는 어디에서합니까? 아마도 Db가있는 모듈을 가져 오지 않았을 수 있습니다. – user568109
mongodb 모듈을 가져 오는 것을 잊었습니다. 그것이 잘 작동하는지 확인하십시오. 답변 감사합니다 – Ramesh