title: saving form-elements in an array using mongoose
body: <p>i am trying to develop a MEAN app, i am able to send data from front end to back end server, i am able to push <strong>array</strong> of data in mongoose schema, but i am not able to push the <strong>Object elements</strong> inside the array one by one. my server code looks like</p>
  
  <pre><code> router.post('/', function(req, res) {
        console.log(req.body.details);//getting data in array
       console.log(req.body.academics);//getting data in array
       console.log(req.body.trainings);////getting data in *object*
       var detail = req.body.details;
       console.log(detail.city); // i can get data here 
       var register = new recruit(req.body);
  
  register.contact.push({
      city: detail.city || "",//but the data doesnot get inserted now
      state: detail.state || "",
      municipalityVdc: detail.municipalityVdc || "",
      wardNo: detail.wardNo || "",
      houseNo: detail.houseNo || "",
      streetName: detail.streetName || "",
      contactNo: detail.contactNo || "",
      eContactNo: detail.eContactNo || "",
      email: detail.email || "",
      aEmail: detail.aEmail || "",
      facebookId: detail.facebookId || "",
      linkedinId: detail.linkedinId || ""
  });
  register.qualification.push(req.body.academics);// array of data are inserted inside the mongoose schema
  register.trainings.push(req.body.trainings);// data get inserted
  </code></pre>
  
  <p>it is fine saving all data at once but i am trying to manage data in different array. i have got another array too where details are to be inserted</p>
  
  <pre><code>  register.basicDetails.push({
      firstName: detail.firstName || "",//no data are inserted here too
      lastName: detail.lastName || "",
      fathersName: detail.fathersName || "",
      dob: detail.dob || "",
      marritalStatus: detail.marritalStatus || "",
      drivingLicense: detail.drivingLicense || "",
      vehicle: detail.vehicle || "",
      gender: detail.gender || "",
      photo: req.file.originalname || "",
      jobTitle: detail.jobTitle || "",
      experiance: detail.experiance || ""
  });
  register.save(function(err, respond) {
      if (err) {
          throw err;
      } else {
          res.json(respond);
      }
  })
  </code></pre>
  
  <p>});
  module.exports = router;</p>
  
  <p>my code works if i make object of mongoose module and directly save it to database but only <strong>array</strong> are inserted not <strong>objects</strong>,
  my working code looks like</p>
  
  <pre><code> router.post('/', function(req, res) {
  
  var register = new recruit(req.body);
  
  register.save(function(err, respond) {
      if (err) {
          throw err;
      } else {
          res.json(respond);
      }
     })
   });
   module.exports = router;
  </code></pre>
  
  <p>some one please enlighten me about managing  data using mongoose, and correct me where i am wrong. will highly appreciate any response.</p>