How to save array of inputs to a child schema in a nested mongoose schema?
<p>I am trying to save a survey which contains multiples questions. Each time I enter a question and the answers and click the save button it should push it to the question array and at last when I click the save survey button the whole question should be saved under the parent schema 'survey'. </p>

<p>How can I do this with nodejs and mongoose? What I tried is here....</p>

<p><strong>Mongoose schema</strong></p>

<pre><code> var mongoose = require("mongoose");
 var Schema = mongoose.Schema;

 var SurveySchema = new Schema({
    surveyname: String,
    question  : [{
        que: String,
        ans1: String,
        ans2: String,
        ans3: String,
        ans4: String

        }]
    });

 module.exports=mongoose.model('Survey',SurveySchema);
</code></pre>

<p>The js file where I save the inputs to the schema</p>

<pre><code>var express = require('express');
var router = express.Router();
var survey = require('../models/QBank');

router.post('/', function(req, res, next){ 
  new survey({
    surveyname: req.body.sname,
    for(var i=0;i&lt;5;i++){
      question.question.push({
        que: req.body.que,
        ans1: req.body.ans1,
        ans2: req.body.ans2,
        ans3: req.body.ans3,
        ans4: req.body.ans4
      });
    }

    }).save(function(err, doc){
      if(err) res.json(err);
      else
          req.flash('success_msg', 'Question saved to QBank');  
      res.redirect("/CreateSurvey");

    });

});

module.exports = router;
</code></pre>

<p>I am stuck  here with my project.</p>