Mongoose is saying I have 46 records, mongoDB says I have zero?


The following test script says I have 46 records:

var mongoose = require('mongoose'),
Schema = mongoose.Schema;

var DealSchema = new Schema({
title : String,

var Deal = mongoose.model('Deal', DealSchema);

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

While if I try to read the cords using the mongo shell I get a different story:

$ 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()
> db.dealsite.Deal.count()

Where are my records hiding?

Problem courtesy of: Kit Sunde


In MongoDB, try:

use dealsite

If you create a Mongoose model called “Deal”, it will create and use a MongoDB collection called “deals”.

Solution courtesy of: Mike Scott

View additional discussion.