Thursday 25 October 2018

How to add title to array of objects returned with express find()?

Sorry I'm new to node and what I know so far is just built using a tutorial for referenceapi.get('/', (req, res) => { let city = req.query.city; People.find({ city: city }, (err, people) => { if (err) { res.send(err); } res.json(people); }); }); this returns the objects as:{ name: "example", id: "123123123" }, { name: "example", id: "123123123" } But I would like them to be nested as objects of another group called People. How would I accomplish that?

Submitted October 25, 2018 at 04:46PM by SumTingWong59

No comments:

Post a Comment