title: Looking for Best Approach For update one in Mongoose
body: <p>I am still kind of new to Mongoose in general. I am building my blogging app which has backend based on Node and MongoDB, I am using Angular for frontend.</p>
  
  <p>I am creating my Restful API which is supposed to allow user click on a post and update it.  However, I don't know for sure whether I am doing it the right way here.</p>
  
  <p>This is the schema for my post:</p>
  
  <pre><code>const mongoose = require('mongoose');
  
  // Schema Is ONly bluePrint
  var postSchema = mongoose.Schema({
    title: {type: String, required: true },
    content: {type: String, required: true},
  }, {timestamps: true});
  
  module.exports =  mongoose.model("Post", postSchema);
  </code></pre>
  
  <p>In my angular service, I have this function to help me to send the http request to my backend server, the id for this function comes from backend mongoDB, title and content is from the form on the page</p>
  
  <pre><code>  updatePost(id: string, title: string, content: string) {
      console.log('start posts.service-&gt;updatePost()');
      const post: Post = {
        id: id,
        title: title,
        content: content
      };
      this._http.put(`http://localhost:3000/api/posts/${id}`, post)
        .subscribe(res =&gt; console.log(res));
    }
  </code></pre>
  
  <p>It appears to me that there are at least couple of ways of approaching this for creating my API </p>
  
  <p>Method 1 ( works but highly doubt if this is good practice):
  here I am passing the id retrieved from mongoDB back to server via my service.ts file to avoid the 'modifying immutable field _id' error </p>
  
  <pre><code>app.put("/api/posts/:id", (req,res)=&gt;{
    console.log('update api called:', req.params.id);
    const post = new Post({
      id: req.body.id,
      title: req.body.title,
      content: req.body.content
    });
  
    Post.updateOne({_id: req.params.id}, post).then( result=&gt; {
      console.log(result);
      res.json({message:"Update successful!"});
    });
  });
  </code></pre>
  
  <p>Method 2 I consider this is more robust than method 1 but still I don't think its good practice:</p>
  
  <pre><code>  app.put("/api/posts/:id", (req, res)=&gt; {
    Post.findOne(
        {_id:req.params.id},(err,post)=&gt;{
            if(err){
                console.log('Post Not found!');
                res.json({message:"Error",error:err});
            }else{
                console.log('Found post:',post);
                post.title=req.body.title;
                post.content=req.body.content;
                post.save((err,p)=&gt;{
                    if(err){
                        console.log('Save from update failed!');
                        res.json({message:"Error",error:err});
                    }else{
                        res.json({message:"update success",data:p});
                    }   
                })
            }
        }
    );
  });
  </code></pre>
  
  <p>I am open to all opinions in the hope that I can learn something from guru of Mongoose and Restful : )</p>