Reputation: 8263
I'm new to mongoose
and mongodb
.Using this tutorial to create my first application.
When i use
mongoosemodel.find()
it returns only the Id of the document.
I have gone through the mongoose documentation still i'm confused about this.
// define model =================
var User = mongoose.model('User',
{
firstName :String,
lastName :String,
});
Query
User.find(function(err,users){
if(err)
response.send(err)
console.log(users);
response.json(users);
});
Is this a default behavior of mongoose ?
Do i need to explicitly include my field name in the query.?
How would i get all field ?
Please let me know what i'm doing wrong.
Upvotes: 1
Views: 2206
Reputation: 543
That tutorial is missing the mongoose.Schema configuration so your "Create" isn't actually setting those two properties.
Try this when defining your model:
// define model =================
var User = mongoose.model('User',
new mongoose.Schema({
firstName :String,
lastName :String,
}));
Upvotes: 4