title: Trying to increment by 1 every time the page is viewed
body: <p>I'm trying to figure out how to update the field by incrementing +1 each time the page is visited and if it has never been visited then add it to the DB. </p>
  
  <p>Currently, this is what I have got but it does not seem to do much. I must have gone wrong somewhere and I have not yet implemented the part where if the page has never been viewed then create a new object in the array which is stored in the database.</p>
  
  <p>Little note: Where I created the map they do match with the same ID if I view the page with the same ID as the one stored in the database but no increment happens.</p>
  
  <pre><code>exports.pageVisitCount = (req, res, next) =&gt; {
    User.findById({
      _id: req.userData.userId
    }, 'visits', function (err, pageVists) {
      if (err) {
        res.status(401).json({
          message: "Error Occured!"
        })
      } else {
        const pageCounts = pageVists.visits;
        pageCounts.map(page =&gt; {
          const postViewed = req.body.postId;
          if (page.postId.toString() === postViewed) {
            User.findByIdAndUpdate({
                _id: req.userData.userId
              }, {
                $set: {
                  visits: [{
                    "postId": postViewed,
                    $inc: { visitCount: 1 }
                  }]
                }
              }, {
                upsert: false
              },
              (err) =&gt; {
                if (err) {
                  res.status(401).json({
                    message: "Error Occured!"
                  })
                } else {
                  res.status(200).json({
                    message: "Update successful!"
                  })
                }
              });
          }
        });
      }
    });
  }
  </code></pre>
  
  <p>This is the schema I am using: </p>
  
  <pre><code>const visitsSchema = new Schema ({
    postId: {
      type: String
    },
    visitCount: {
      type: Number
    }
  })
  
  const userSchema = mongoose.Schema({
    email: {
      type: String,
      required: true,
      unique: true
    },
    password: {
      type: String,
      required: true
    },
    role: {
      type: String,
      required: true
    },
    answers: {
      type: String
    },
    visits: [visitsSchema]
  });
  </code></pre>
  
  <p>Any feedback would be highly appreciated, I would like to mention that I am new to backend, thanks! </p>