因为MongoDB
是文档型数据库,所以它没有关系型数据库joins
(数据库的两张表通过"外键",建立连接关系。) 特性。也就是在建立数据的关联时会比较麻烦。为了解决这个问题,Mongoose
封装了一个Population
功能。使用Population
可以实现在一个 document 中填充其他 collection(s) 的 document(s)。
ObjectId
, Number
, String
, 和 Buffer
作为 refs。
语法:
populate(path, [select], [model], [match], [options])
参数:
path
< Object,