以下测试脚本说我有 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 shell 读取电线,我会得到一个不同的故事:
$ 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
我的记录藏在哪里?