Mongodb嵌套模型

我的模型看起来像下面

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

在获取数据的时候我怎样才能得到结果呢。

 posts=[ {Post:'abc',Date:'10/10/2016',User:{UserName:'testuser1',Mobile:'9090123456'}}, {Post:'abc',Date:'10/10/2016',User:{UserName:'testuser2',Mobile:'9090123457'}} ] 

你必须添加

 User : {type : Schema.Types.ObjectId,ref:'User'} 

在你的邮政模型

当你查询你必须做的

 db.Post.find({}).populate('User')