title: PUT custom find update REST API Node Js
body: <p>I have created a basic REST api in Node js and Mongodb. I want to update the value using Find with Custom Parameter such as <code>name</code>. I am able to get the user using Custom GET method but it it not working in PUT/POST Method.</p>
  
  <p>Here is the Schema:</p>
  
  <pre><code>{
      name:String,
      value:Number
  }
  </code></pre>
  
  <p>Here is the code:</p>
  
  <p>//v1/api/users/:name -Update </p>
  
  <pre><code>api.put('/users/:name',(req,res)=&gt;{
  Users.find({name:req.params.name},(err,user)=&gt;{
  if(err){
  
    res.send(err);
  }
  console.log(req.body.name);
  console.log(req.body.value);
  
  
  user.value= req.body.value;
  user.save(err =&gt; {
    if(err){
  
      res.send(err);
    }
    res.json({message:'Updated '});
  
     });
  
  
     });
   });
  </code></pre>
  
  <p>Now for example if the <code>mongoDb</code> has <code>"name":"sam"</code> and I use `localhost:3000/v1/api/users/sam`` and body as </p>
  
  <p>1.<code>{"value":300}</code>, I get error</p>
  
  <blockquote>
    <p>Cannot set property 'name' of undefined</p>
  </blockquote>
  
  <p>2.When I logged the 1st error, I came to know that not defining the name was giving me the error. so I used this <code>{"name":"sam","value":300}</code> and now the error is user. save is not a function. </p>
  
  <p>Updating using <code>FindById</code> is working,but in client case,the user cannot get the id from the database, so I tried the above method.</p>
  
  <p>Please Help me out</p>