F.H*_*.H. 8 mongoose mongodb node.js
我注意到 mongoose 4.7.3 中的 .populate 函数为每次查找在数据库上运行单独的查询:
db.House
.populate('ownerId')
.exec((err, result) => {
..
Run Code Online (Sandbox Code Playgroud)
使用聚合管道,我们可以使用单个查询查找多个集合:
db.House.aggregate([
{
$lookup:
{
from: 'owners',
localField: 'ownerId',
foreignField: '_id',
as: 'owner',
},
Run Code Online (Sandbox Code Playgroud)
mongoose 使用 .populate 进行单独查询的原因是什么?聚合函数在查找上的性能是否更高?
归档时间: |
|
查看次数: |
3851 次 |
最近记录: |