mongoose populate用於對外鍵(objectid)字段的擴展,省去前段二次查詢數據庫的麻煩。html
參考:http://mongoosejs.com/docs/populate.html數據庫
有2個特殊的用法:數組
1. 對objectid數組的populate,這個和單個objectid的populate同樣;mongoose
2. Populating across multiple levels,即對objectid 下的objectid對象的populatehtm
User. findOne({ name: 'Val' }).對象
populate({ip
path: 'friends', // Get friends of friends - populate the 'friends' array for every friend populate:get
{ ejs
path: 'friends'擴展
}
}
);