title: Update data in mongoDB with Moongoose and AngularJs
body: <p>I'm using NodeJS, AngularJS, and MongoDB with mongoose to make a website. I'm having some trouble for modify an object in mongoDB. I follow a tutorial and everything work with the exemple. But I try with another table, the name of the new table is post and I have a problem when I want to change a value in the table.</p>
  
  <p>Here is my Model :</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  var mongoose = require('mongoose');
  var Todo = require('../models/Post.js');
  
      var PostSchema = new mongoose.Schema({
          nomReseau : String,
          corps : String,
          etat : String,
          section : String
      });
  var Post = mongoose.model('PostReseaux', PostSchema);
  module.exports = Post;
  </code></pre>
  
  <p>Here you can see the html :</p>
  
  <pre><code> &lt;ul&gt;
      &lt;li ng-repeat="post in posts "&gt;
          &lt;div class="card blue-grey darken-1"&gt;
              &lt;div class="card-content white-text"&gt;
                  &lt;span class="card-title"&gt;Ticket&lt;/span&gt;
                  &lt;p&gt;
                      &lt;a ng-show="!editing[$index]" href="#/{{post._id}}"&gt;{{post.corps}}&lt;/a&gt;
                  &lt;/p&gt;
                  &lt;input type="checkbox" ng-model="post.etat" ng-change="update($index)"&gt;
                  &lt;button ng-show="!editing[$index]" ng-click="edit($index)"&gt;Editer&lt;/button&gt;
                  &lt;button ng-show="!editing[$index]" ng-click="remove($index)"&gt;Supprimer&lt;/button&gt;
                  &lt;button ng-show="!editing[$index]" ng-click="passer($index)"&gt;Passer&lt;/button&gt;
  
                  &lt;input ng-show="editing[$index]" type="text" ng-model="post.corps"&gt;
                  &lt;button ng-show="editing[$index]" ng-click="update($index)"&gt;Confirmer&lt;/button&gt;
                  &lt;button ng-show="editing[$index]" ng-click="cancel($index)"&gt;Annuler&lt;/button&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/li&gt;
  &lt;/ul&gt;
  &lt;a class="waves-effect waves-light btn" ng-click="save()"&gt;Créer ticket&lt;/a&gt;
  </code></pre>
  
  <p>It's a simple ng-repeat who show every post in my database, if I use the remove or the save functions everything works I can add or remove a post in the db.</p>
  
  <p>Here is the controller :</p>
  
  <pre><code>angular.module('app').controller('Feedback', ['$scope','$location','Posts', function($scope, $location, Posts) {
      $scope.title = 'Feedbacks';
      $(".button-collapse").sideNav();
      $scope.editing = [];
      $scope.posts= Posts.query();
  
      $scope.save = function(){
          if($scope.CorpsTicket.length &lt; 1) return;
          var post = new Posts({ nomReseau: "Google+", corps : "test", etat : "aTraiter", section :"feedback" });
  
          post.$save(function(){
              $scope.posts.push(post);
          });
      }
  
      $scope.update = function(index){
          var post = $scope.posts[index].etat;
          Posts.update({id: post._id}, post);
          $scope.editing[index] = false;
      }
  
      $scope.passer = function(index){
          var post = $scope.posts[index];
          post.etat = "enCours";
          Posts.update({id: post._id}, post);
          $scope.editing[index] = false;
      }
  
      $scope.edit = function(index){
          $scope.editing[index] = angular.copy($scope.posts[index]);
      }
  
      $scope.cancel = function(index){
          $scope.posts[index] = angular.copy($scope.editing[index]);
          $scope.editing[index] = false;
      }
  
      $scope.remove = function(index){
          var post = $scope.posts[index];
          Posts.remove({id: post._id}, function(){
              $scope.posts.splice(index, 1);
          });
      }
  
  
  }])
  </code></pre>
  
  <p>And here is the js for the backend :</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  
  var mongoose = require('mongoose');
  var Post = require('../models/Post.js');
  
  /* GET /post listing. */
  router.get('/', function(req, res, next) {
      Post.find(function (err, posts) {
          if (err) return next(err);
          res.json(posts);
      });
  });
  
  
  /* POST /post */
  router.post('/', function(req, res, next) {
      Post.create(req.body, function (err, post) {
          if (err) return next(err);
          res.json(post);
  });
  });
  
  /* GET /todos/id */
  router.get('/:id', function(req, res, next) {
      Post.findById(req.params.id, function (err, post) {
          if (err) return next(err);
          res.json(post);
      });
  });
  
  
  /* PUT /todos/:id */
  router.put('/:id', function(req, res, next) {
      Post.findByIdAndUpdate(req.params.id, req.body, function (err, post) {
          if (err) return next(err);
          res.json(post);
      });
  });
  
  /* DELETE /todos/:id */
  router.delete('/:id', function(req, res, next) {
      Post.findByIdAndRemove(req.params.id, req.body, function (err, post) {
          if (err) return next(err);
          res.json(post);
      });
  });
  
  module.exports = router;
  </code></pre>
  
  <p>But if I click on edit($index) and I change the value of post.corps and I click on Confirmer the value change in the screen but not change in the database.</p>
  
  <p>I think I have a problem with the update function, but I don't know what it is.
  Like is say, I have done a tutorial and, with the table create in the tutorial, everything works I can modify a value, but I got this bug with this new Table post.</p>
  
  <p>Thanks</p>