У меня есть User
модель, схема приведена ниже, я пытаюсь заполнить подкатегории в deals
и wishes
, но не могу.
image: { type: String, default: 'NA' },
firstName: { type: String, default: 'first name' },
lastName: { type: String, default: 'last name' },
email: { type: String, lowercase: true, unique: true, trim: true },
password: { type: String, min: 6 },
deals: [
{
_id : false,
category: { type: Schema.Types.ObjectId, ref: 'Category' },
subCategory: [{ type: Schema.Types.ObjectId, ref: 'Subcategory' }]
}
],
wishes: [
{
_id : false,
category: { type: Schema.Types.ObjectId, ref: 'Category' },
subCategory: [{ type: Schema.Types.ObjectId, ref: 'Subcategory' }]
}
]
Вотпример ответа JSON
"deals": [
{
"subCategory": [
"5bc419cea25fc606153bdbe4",
"5bc419cea25fc606153bdbe3"
],
"category": "5bc419cea25fc606153bdbe2"
}
],
"wishes": [
{
"subCategory": [
"5bc41a40a25fc606153bdbe5",
"5bc41a40a25fc606153bdbe7"
],
"category": "5bc41a40a25fc606153bdbe5"
}
]
Я могу заполнить deals.category
, но не deals.subcategory
// method to get users with populated deals and wishes
allUsers: async (req, res, next) => {
const users = await User.find({})
.populate('deals.category', 'id name')
.populate('wishes.category', 'id name')
.populate('deals.subCategory');
return respondSuccess(res, null, users);
},
// currently the response i'm getting
"deals": [
{
"subCategory": [],
"category": {
"_id": "5bc419cea25fc606153bdbe2",
"name": "Auto"
}
}
],
"wishes": [
{
"subCategory": [
"5bc41a40a25fc606153bdbe5",
"5bc41a40a25fc606153bdbe7"
],
"category": {
"_id": "5bc41a40a25fc606153bdbe5",
"name": "Baby Sitting"
}
}
]
в поисках столь необходимой помощи.
спасибо