title: mongoose, post data using form-data
body: <p>so I wan,t to post data from web form to database
  and this is all of my code</p>
  
  <p><strong>script.js</strong></p>
  
  <pre><code>$scope.save1 =function()
  {
      var input2 = {
          "_id":$scope.iduser,
          "Name":$scope.username,
          "position":$scope.position,
          "level":$scope.level,
          "acclevel":$scope.data.acclevel,
          "status":$scope.status1,
          "pass":$scope.pass
      }
      $http.post("http://localhost:22345/user",input2)
      .success(function(res) {
          if(res.error == 0)
          {
              $scope.status1 = "active";
              $scope.iduser = "";
              $scope.username = "";
              $scope.position = "";
              $scope.level = "";
              $scope.data.acclevel = "";
              $scope.pass = "";
              $scope.IdUser = false;
              alert("save success");
          }
          else
          {
              console.log(res.User);
          }
      });
  }   }]);
  </code></pre>
  
  <p><strong>my rest API (user.js)</strong></p>
  
  <pre><code>app.post("/user",function(req,res){
  
      var users = new user(req.body);
      users.save(function(err,users){
          if(err)
          {
              data['error'] = 1;
              data['User'] = err;
              res.json(data);
          }
          else
          {
              data['error'] = 0;
              res.json(data);
          }
      })
  });
  </code></pre>
  
  <p><strong>models</strong></p>
  
  <pre><code>var mongoose = require("mongoose");
  var Schema = mongoose.Schema;
  
  var user = new Schema({
  _id : String,
  Name : String,
  position : String,
  level : String,
  status : String,
  pass : String},{ collection: 'user'});
  var user = mongoose.model("user",user);
  module.exports.user = user;
  </code></pre>
  
  <p>when i try to post using postman using form-data, i always get an error result but if i use x-www-form-urlencoded, i can get success result, so whats the problem from mya code. thank you</p>
  
  <p><strong>update</strong></p>
  
  <p>finaly I found the problem, it's happend when I try to crate header (Access-Control-Allow-Origin,Access-Control-Allow-Methods,etc) co I change it with this</p>
  
  <pre><code>app.use(function (req,res,next) {
  res.header("Access-Control-Allow-Origin","*");     
  res.header('Access-Control-Allow-Methods','POST,GET,PUT,DELETE,OPTIONS');
  res.header("Access-Control-Allow-Headers","X-Requested-With,X-HTTP-Methods-Override,Content-Type,Accept,Cache-Control, Pragma, Origin,Authorization, Content-Type");
  res.header("Access-Control-Allow-Credentials","true");
  if ('OPTIONS' == req.method){
      return res.send(200);
  }
  next();
  });
  </code></pre>
  
  <p>so thanks for all answers</p>