0

I got a strange behaviur using mongoose. I got empty array, but my document have some document. This is my Account.js :

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

var accountSchema = mongoose.Schema({
    username: String,
    password: String,
    cover: String,
    createAt: {type: Date, default: Date.now},
    subscriber_email: String
});

var Account = module.exports = mongoose.model('account', accountSchema);

module.exports = Account;

This is my controller, the filename is home.js

var User = require('../models/User');
var Account = require('../models/Account');

exports.getNumberOfAccounts = function(req, res) {
    Account.find({}, function(err,response){
        console.log(response)
    });
}

How I can it in server.js

var app = express();
var homeController = require('./controllers/home');
app.post('/getNumberOfAccounts', homeController.getNumberOfAccounts);

Which part I've done wrong? I always get empty array.

Maria Jane
  • 2,353
  • 6
  • 23
  • 39

0 Answers0