I'm trying to reduce my API data size to remove unwanted data. I have schema like this
const course = mongoose.Schema(
{
course_name: { type: String, require: true },
disabled: { type: String, required: true, default: false },
subject_ids: [
{
type: mongoose.Schema.ObjectId,
ref: 'subject',
require: true,
},
],
},
{ timestamps: true }
);
after applying the find query i have data like this
{
"disabled": "false",
"subject_ids": [
{
"disabled": "false",
"_id": "60b0bdd5cd7bd635ecf07cd5",
"subject_name": "CSS",
"createdAt": "2021-05-28T09:54:29.147Z",
"updatedAt": "2021-05-28T09:54:29.147Z",
"__v": 0
},
{
"disabled": "false",
"_id": "60b0bdd5cd7bd635ecf07cd7",
"subject_name": "Jquery",
"createdAt": "2021-05-28T09:54:29.147Z",
"updatedAt": "2021-05-28T09:54:29.147Z",
"__v": 0
}
],
"_id": "60b0e3f3012b2b272432e9f9",
"course_name": "Data Science",
"createdAt": "2021-05-28T12:37:07.103Z"
}
API I have tried something like this. I already remove data from the outside array, but I don't know how I can remove it from the inside. I do lots of google search but I didn't get
router.get('/get-course/:status', async (req, res) => {
try {
const data = await COURSE.find({})
.populate('subject_ids')
.select({ updatedAt: 0, __v: 0 })
.exec();
res.json(data);
} catch (error) {
res.status(404).json({ err: 1, message: error.message, error });
}
});
I want data should be like this
{
"disabled": "false",
"subject_ids": [
{
"_id": "60b0bdd5cd7bd635ecf07cd5",
"subject_name": "CSS",
},
{
"_id": "60b0bdd5cd7bd635ecf07cd7",
"subject_name": "Jquery",
}
],
"_id": "60b0e3f3012b2b272432e9f9",
"course_name": "Data Science",
"createdAt": "2021-05-28T12:37:07.103Z"
}
How to get specific data from array