My json data in mongoDB, example:
{
"_id": 1,
"name": "ABC",
"parentID": null
},
{
"_id": 2,
"name": "ABC.txt",
"parentID": 1
},
{
"_id": 3,
"name": "ABCD",
"parentID": 1
},
{
"_id": 4,
"name": "ABC 3",
"parentID": 3
},
{
"_id": 5,
"name": "ABCDFE",
"parentID": null
}
]
how can i query find only Folder1 and children of Folder1 but ignore Folder2 in mongoDB like this by nodejs expressjs:
{ "_id": 1, "name": "ABC", "parentID": null }, { "_id": 2, "name": "ABC.txt", "parentID": 1 }, { "_id": 3, "name": "ABCD", "parentID": 1 }, { "_id": 4, "name": "ABC 3", "parentID": 3 } ]
This is my code:
exports.getProofFolderById = async (req, res, next) => {
const file = await Proof.find({ _id: req.params.id})
if(!file) {
next(new Error("Folder not found!!!"))
}
res.status(200).json({
success: true,
file
})
}
Thanks for help me ❤️