Я хочу перечислить пользователей и найти комментарии в другой коллекции, используя тот же запрос.
Это моя схема пользователей:
Schema({
cod: {
type: String,
require: true
},
name: {
type: String,
required: true
}
})
И это моя схема комментариев:
Schema({
user: {
type: Schema.Types.ObjectId,
ref: 'users'
},
post: {
type: Schema.Types.ObjectId,
ref: 'posts'
},
comment: {
type: String,
required: true
}
})
Я хочу получить вот такие:
{
_id: 5eee97c18b83e338bcbfa8f9,
name: 'Cool Name',
cod: 'CN001',
comments: [{
_id: ObjectId(...)
post: ObjectId(...),
comment: 'comment 1'
},
{
_id: ObjectId(...)
post: ObjectId(...),
comment: 'comment 2'
}
]
}
возможно ли?
Спасибо!