title: Storing array of objects in mongodb using mongoose
body: <p>Can anybody provide a solution to this? I am getting an array of objects in req.body . I am looking for a way to store it in MongoDB using Mongoose.</p>
  
  <p><strong>MySchema</strong>:</p>
  
  <pre><code>const hobbySchema = new Schema({
  
       hobbies:[{ 
           hobby : {type:String}
       }]
  },{collection:'hobby'});
  </code></pre>
  
  <p><strong>req.body</strong></p>
  
  <pre><code>[{ newHobby:'Hobby 1'},{ newHobby:'Hobby 2'},{ newHobby:'Hobby 3'}]
  </code></pre>
  
  <p><strong>API part</strong></p>
  
  <pre><code>router.post('/hobby',(req,res)=&gt;{
          console.log(req.body);
          let hobby = new Hobby({
                 hobbies: [{
                              hobby: req.body.newHobby // I don't know how to store it in mongo
                     }]
          });
          hobby.save((err)=&gt;{
              if(err){
                  res.json({ success:false , message:err});
              } else {
                  res.json({ success:true , message:'Hobbies saved!'});
              }
          });
  });
  </code></pre>