Eldho
Eldho

Reputation: 8263

Mongoose only returning id of the document

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);
});

Please let me know what i'm doing wrong.

Upvotes: 1

Views: 2206

Answers (1)

xianwill
xianwill

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

Related Questions