Q:

Mongodb Nested model

My model looks like following
User Model
{
    UserName:'string',
    Mobile: string
}

Post Model
{
    Post:string,
    Date: { type: Date, default: Date.now },
    User: 'ObjectId'
}

While getting data How can I get result like.
posts=[
{Post:'abc',Date:'10/10/2016',User:{UserName:'testuser1',Mobile:'9090123456'}},
{Post:'abc',Date:'10/10/2016',User:{UserName:'testuser2',Mobile:'9090123457'}}
]

A:

You have to add
User : {type : Schema.Types.ObjectId,ref:'User'}

in your Post Model
and when you query you have to do 
db.Post.find({}).populate('User')

