mongoose populate

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'扩展

     }

}

);

相关文章
相关标签/搜索