こんにちは私はこのコードを機能させようとしていますが、コードの何が問題になっているのか理解できませんでした。接続が開いている場合は、「ここに...」と出力されているはずです。また、「mongod」のコンソールを見ると、接続が開かれていることが示されていますが、何も出力されません。
var Db = require('mongodb').Db;
var Server = require('mongodb').Server;
var client = new Db('test1', new Server('127.0.0.1', 27017, {}));
var Vocabulary = function() {
function get(german_vocab) {
client.open(function(err, pClient) {
console.log("here...")
client.collection('test1', function(err, collection) {
collection.insert({name:"myself"});
});
client.collection.find().toArray(function(err, results) {
console.log(results);
});
});
}
return {
get : get
};
}
module.exports = Vocabulary;
var vocab = Vocabulary();
vocab.get("Ich"); // Nothing shows in this line.
また、データベースが作成されていないことを確認しました。何かが挿入されると、mongodbデータベースは怠惰に作成されると思いましたか?
どうもありがとう。