次のテストスクリプトは、46のレコードがあることを示しています。
var mongoose = require('mongoose'),
Schema = mongoose.Schema;
var DealSchema = new Schema({
title : String,
});
var Deal = mongoose.model('Deal', DealSchema);
mongoose.connect('mongodb://localhost/dealsite');
mongoose.connection.on("open", function(){
console.log("Mongoose connected");
Deal.count({}, function( err, count){
console.log( "Records:", count );
})
});
出力:
$ node testmongo.js
Mongoose connected
Records: 46
一方、mongoシェルを使用してコードを読み取ろうとすると、別の話が得られます。
$ mongo localhost/dealsite
MongoDB shell version: 1.4.4
url: localhost/dealsite
connecting to: localhost/dealsite
type "exit" to exit
type "help" for help
> db.dealsite.count()
0
> db.dealsite.Deal.count()
0
私の記録はどこに隠れていますか?