title: To search for document and then search for array element inside those document in mongoDB?
body: <p>I have been trying to make an upvote and downvote feature for my website. Here is my schema </p>
  
  <pre><code>{
  "_id" : ObjectId("5aa639cb4add7a1c58507ac1"),
  "vote" : -7,
  "votedBy" : [],
  "Fbid" : "109590486545309",
  "imageId" : "86i1dr8apv",
  "email" : "emnnevbjyo_1520686942@tfbnw.net",
  "event" : "selfie",
  "__v" : 0}
  </code></pre>
  
  <p>Now, what is am trying is to lookup my documents with <strong>imageId</strong>, and then look in the array of <strong>votedBy</strong> for specific voter. If the query results with some value act according to the logic of upvoting or downvoting. Here is my upvote and downvote code</p>
  
  <pre><code>app.get('/:id/love', (req, res) =&gt; {
  console.log("Hitting");
  var image_Id = req.params.id;
  var fb_id = req.user.id;
  var query = {
      "imageId": image_Id
  }
  var upvote = {
      $inc: {
          vote: 1
      },
      $push: {
          votedBy: req.user.id
      }
  }
  
  var downvote = {
      $pull: {
          votedBy: req.user.id
      },
      $inc: {
          vote: -1
      }
  }
  likeImformation.find({
      "imageId": image_Id
  }, {
      "votedBy": fb_id
  }).count(function(err, count_num){
      if(count_num===0){
          likeImformation.findOneAndUpdate(query, upvote, function (err, voted) {
              if (err) {
                  res.status(404)
              } else {
                  console.log("upvoted");
                  res.send("upvoted");
              }
          });
      }
      else if(count_num&gt;0){
          console.log(count_num);
          likeImformation.findOneAndUpdate(query, downvote, function (err, voted) {
              if (err) {
                  res.status(404)
              } else {
                  console.log("downupvoted");
                  res.send("downvoted");
              }
          });
      }
  })
  </code></pre>
  
  <p>The problem is I am unable to write the query, which would search for the document and then in the document search for the array element and match it with the "votedBy".</p>