title: Cannot update mogodb object with axios.put in Mern stack app
body: <p>I need to update my &quot;comment&quot; object from my mongodb database &quot;comments&quot; collection. More specifically, when I press the &quot;Like&quot; button, I want to send a put request with axios where I can add + 1 to the &quot;likes&quot; from &quot;comment&quot; object.</p>
  <p>All other actions are working fine(getting comments, adding them, etc), the only one I'm struggling with is Updating the comment likes.</p>
  <p>I would really appreciate if anybody can help. Thanks in advance!</p>
  <p>Down here I added my code:</p>
  <p>//--------CommentComponent.js</p>
  <pre><code>import React, { useState, useEffect } from 'react'
  import { useSelector, useDispatch } from 'react-redux'
  import { getComments, updateComment } from '../actions/commentActions'
  
  const PostPage = ({ match }) =&gt; {
      
  const commentz = useSelector(store =&gt; store.comment.comments)
  const dispatch = useDispatch()
  
  useEffect(() =&gt; {
      dispatch(getComments())
  }, [dispatch])
  
  const handleLike = e =&gt; {
      dispatch(updateComment(e.target.id))
  }
  
  return (
      {commentz ? commentz.map(comm =&gt; 
          comm.forWich === match.params.id ?
              &lt;div key={comm._id} className={styles.comment}&gt;
                  &lt;div&gt;
                      &lt;h2&gt;{comm.name}&lt;/h2&gt;
                  &lt;/div&gt;
                  &lt;div&gt;
                       &lt;p&gt;{comm.comment}&lt;/p&gt;
                  &lt;/div&gt;
                       {comm.likes} &lt;button id={comm} onClick={handleLike}&gt;Like&lt;/button&gt;
                  &lt;div&gt;
              &lt;/div&gt;
          : null
      ) : null}
      )
  }
  
  export default PostPage
  </code></pre>
  <p>//-------Comment.js</p>
  <pre><code>const mongoose = require('mongoose');
  const Schema = mongoose.Schema;
  
  // Create Schema
  const CommentSchema = new Schema({
      name: {
          type: String,
          required: true
      },
      email: {
          type: String,
          required: true
      },
      comment: {
          type: String,
          required: true
      },
      forWich: {
          type: String,
          required: true
      },
      likes: {
          type: Number,
          default: 0
      },
      date: {
          type: Date,
          default: Date.now
      }
  });
  
  module.exports = Comment = mongoose.model('comment', CommentSchema);
  </code></pre>
  <p>//-------comments.js</p>
  <pre><code>const express = require('express');
  const router = express.Router();
  
  // Comments Model
  const Comment = require('../../models/Comment');
  
  // @route UPDATE api/comments
  // @desc Update comment
  // @access Public
  router.put('/:id', (req, res, next) =&gt; {
      Comment.findbyId(req.params.id)
         .then(comment =&gt; comment.update(req.body))
         .catch(next);
  })
  
  module.exports = router;
  </code></pre>
  <p>//--------CommentActions.js</p>
  <pre><code>import axios from 'axios';
  import { 
      GET_COMMENTS,
      ADD_COMMENTS,
      COMMENTS_LOADING,
      GO_COMMENTS,
      UPDATE_COMMENTS
  } from './types';
  
  
  
  export const updateComment = comment =&gt; {
      return function(dispatch) {
          axios
              .put(`/api/comments`, comment)
              .then(res =&gt;
                  dispatch({
                      type: UPDATE_COMMENTS,
                      payload: comment
                  })
              )
      }
  }
  </code></pre>
  <p>//--------CommentReducer.js</p>
  <pre><code>import {
      GET_COMMENTS,
      ADD_COMMENTS,
      COMMENTS_LOADING,
      GO_COMMENTS,
      UPDATE_COMMENTS
  } from '../actions/types';
  
  const initialState = {
      comments: []
  }
  
  export default function(state = initialState, action) {
      switch(action.type) {
          case UPDATE_COMMENTS:
              return {
                  ...state,
                  comments: state.comments.map(comm =&gt; comm._id === action.payload._id ? comm.likes = action.payload + 1 : comm.likes)
      }
  }
  }
  </code></pre>