title: Create User in mongoose
body: <p>My Schema is : </p>
  
  <pre><code>var UserSchema = mongoose.Schema({
      name: {type:String},
      city: {type:String},
      accounts: [
          {
              typeA: [
                  {
                      isUsed: String,
                      someInfo: String
                  }
              ]
          },
          {
              typeB: [
                  {
                      isUsed: String,
                      someInfo: String
                  }
              ]
          }
      ]
  });
  </code></pre>
  
  <p>I can insert the document with only name and city. Where: </p>
  
  <pre><code>app.get('/createuser', function(req, res){
      var user = req.body;
      var name = req.body.name;
      var city = req.body.city;
      var type = req.body.type;
  
      User.create(user, function(err, doc){
          if(err) return err;
          else { res.send(doc); }
      }); 
  });
  </code></pre>
  
  <p>I want to insert the value in <code>accounts</code> based on <code>var type = req.body.type;</code>. If the <code>type = typeA</code>, i wan the value for <code>typeA.isUsed = "yes"</code>
  I tried : </p>
  
  <pre><code>app.get('/createuser', function(req, res){
      var user = req.body;
      var name = req.body.name;
      var city = req.body.city;
      var type = req.body.type;
  
      if(type == "typeA"){
  
          user.accounts.typeA.isUser = "1";
          User.create(user, function(err, doc){
          if(err) return err;
          else { res.send(doc); }
      });
      }
      if(type == "typeB"){
  
          user.accounts.typeB.isUser = "1";
          User.create(user, function(err, doc){
          if(err) return err;
          else { res.send(doc); }
      }
  });
  </code></pre>
  
  <p>But this is not working. How can I achieve this?</p>
  
  <p>Many thanks.</p>