I have this deeply nested array issue. My mongoose schema is fine every works well.
The json file looks like below:
{
"_id": "66758c92619555fcd49269e8",
"boards": [
{
"_id": "66758c92619555fcd49269e9",
"columns": [
{
"_id": "66758c92619555fcd49269ea",
"name": "Testy",
"tasks": [
{
"_id": "66758c92619555fcd49269eb",
"description": "",
"status": "Doing",
"subTasks": [
{
"_id": "66758c92619555fcd49269ec",
"isCompleted": false,
"title": "testosota"
}
],
"title": "Testingsies"
}
]
}
],
"name": "stillaTest"
}
]
}
How do I update tasks.subTasks array?, and tasks array, columns array. Updating the boards array is done and quite easy really but the others are a mess in my head right now.
My controller is as follow:
const putSubTask = async(req, res)=>{
const {board, title, col} = req.query
const {id} = req.params
const toUpdate = await Task.findOneAndUpdate({_id:id},
{$push:{"boards.$[board].columns.$[name].tasks.$[title].subTasks":[req.body]}},
{arrayFilters:[{"name.name":col}, {"board.name":board}, {"title.title":title}],new:true})
return res.status(200).json({success:true, message:toUpdate})
}
I’m trying to push to the subTasks array. using postman, I get no errors, just null value returned. I’ve worked with arrays in mongoose before but this one is just nested deep. I’ll be working with more deeply nested arrays and object(deeper than this). So I want to know how to get to an array/object no matter how deeply nested. I’ve tried how I know but it’s not working. thanks for your help.
user25666876 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1