【发布时间】:2020-07-03 22:48:42
【问题描述】:
我正在为我的应用创建一个数据库服务,但只是为一些代码。有很多人口。 那么是否可以添加类似的内容:
if (populateFriends) {
.populate('friends')
}
if (populatePosts) {
.populate('posts')
}
并添加末尾它会自动将其添加到 find().populate('friends').populate('posts');
因为现在我得到了这样的东西:
Action.find({ completed: false, userRole: ROLES.ADMIN }, selection)
.populate({
path: 'tender',
select: 'number description shipper carriers type',
populate: {
path: 'shipper',
select: 'company firstName lastName',
populate: {
path: 'company',
select: 'companyName'
}
}
})
.sort({ creationDate: -1 })
.populate('additionalData.documentId'),
【问题讨论】:
标签: javascript mongoose mongoose-populate