db.collection('cloths').aggregate()
.lookup({
from: 'recommoned',
localField: 'sn',
foreignField: 'coverProductList',
as: 'coverImgUrls',
})
.project({
_id: false,
coverImgUrls: true
})
.match({
coverImgUrls: _.neq([])
})
.replaceRoot({
newRoot: '$coverImgUrls'
})
.end({
success: function (res) {
console.log(res.list)
},
fail: function (err) {
console.error(err)
}
})
上面是会报错的,改成下面的写法就不报错了
.replaceRoot({
newRoot: {
root: '$coverImgUrls'
}
})
