EDIT : Duplicate of : Mongoose find() not returning result
I'm new to nodejs and nosql db.. Today I'm creating an API which read my user collection with two entries :
The problem is that the result is an empty array :
Here is the code :
The model :
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var UserModelSchema = new Schema({
_id: Schema.Types.ObjectId,
user_id:String,
age:{ type: Number },
status:String
});
module.exports = mongoose.model('user', UserModelSchema);
app.js :
//...
var User = require('./app/models/user');
//...
router.route('/users')
// get all the users
.get(function(req, res) {
User.find(function(err, users) {
if (err)
res.send(err);
res.json(users);
});
});