私はできる限りのことを試しましたが、グーグルでいくつかの例を見つけました。例を試しましたが、喜びはありませんでした。私は今本当に立ち往生しています。だから、私はbrew経由でインストールしたMacにmongodbを持っています。うまくいきました。「mongod」でサーバーを起動しましたが、うまくいきました。私はmongointeractiveにいくつかのデータを挿入します。これは、データを取得したときに以下に表示されます。データベース名は「test」、コレクションは「test」です。
> db.test.find()
{ "_id" : ObjectId("4fc27535a36ea778dd6cbdf4"), "a" : "1" }
{ "_id" : ObjectId("4fc27557a36ea778dd6cbdf5"), "Ich" : "I" }
さて、このコードでマングースを使って簡単なモカテストを作成すると。
var Vocabulary = function() {
function get(german_vocab) {
var mongoose = require("mongoose");
mongoose.connect('mongodb://localhost:27017/test');
mongoose.connection.on("open", function(){
console.log("mongodb is connected!!");
});
mongoose.connection.db.collection("test", function (err, collection) {
collection.find().toArray(function(err, results) {
console.log(results);
});
});
}
return {
get : get
};
}
module.exports = Vocabulary;
そしてこれは私のモカテストです
var should = require('should');
var Vocabulary = require('../modules/vocabulary');
describe("Vocabulary", function() {
it("should get a translation of Ich", function() {
var vocabulary = Vocabulary();
vocabulary.get("Ich");
});
});
これは私がモカから得たものです
Vocabulary
✓ should get a translation of Ich (161ms)
✔ 1 test complete (163ms)
ご覧のとおり、「mongodbが接続されています!」と表示されることはありません。また、find()メソッドでは、何も出力されません。
私を助けてください。どうもありがとう。