i want to manufacture the result of mysql in node js
i want to make the result like this
[ { "m_idx" :1 , "contents" : { "m_name" : "a", "m_name" : "b", } }, "m_idx" :2, "contents" : { "m_name" : "c", } } ] but my result is
{ "m_idx": 1, "contents": [ { "m_name": "a" } ] }, { "m_idx": 1, "contents": [ { "m_name": "b" } ] }, i don't know how to manufacture the result could any one help me...? pls this is what i practiced code
let result = []; let categories = []; connection.query(sql, function (err, rows) { if (res.status(200)) { rows.forEach(function (row, index) { let variable = { m_idx: row.m_idx, contents: [] }; categories.push(variable); variable.contents.push({ m_name: row.m_name, name: row.name, }) }); res.json(categories); } }); and my database result is like this
----- |1|a| |1|b| |2|c| -----