[Vuejs]-Post item with mix of objects and arrays to Mongo – the array does not post data

0πŸ‘

βœ…

In your create method,

let data = { 
        month: this.month,
        projects: [
          {
            code: this.projects.code,
            name: this.projects.name,
            staff: this.projects.staff,
            support: this.projects.supported
          }
        ],

You are sending projects as an array and accessing it as an object in your API β€”>
req.body.projects.code
Do the following change in your API and it should work.

app.post('/api/report/create', (req, res) => {
  const report = new Report({
    month: req.body.month,
    projects: req.body.projects 
})

Leave a comment