title: mongodb and js check if the document already exist in the array
body: <p>The goal is go check if the course already enrolled by the student.</p>
  <p>User Token is saved in the local storage.
  I also acquire the _id of the user in the database.</p>
  <pre><code>let urlValues = new URLSearchParams(window.location.search)
  let id = urlValues.get('courseId')
  
  let token = localStorage.getItem('token')
  let userId = localStorage.getItem('id')
  
  let name = document.querySelector(&quot;#courseName&quot;)
  let price = document.querySelector(&quot;#coursePrice&quot;)
  let desc = document.querySelector(&quot;#courseDesc&quot;)
  let enroll = document.querySelector(&quot;#enrollmentContainer&quot;)
  
  fetch(`http://localhost:4000/api/courses/${id}`).then(res =&gt; res.json()).then(convertedData =&gt; {
  
      name.innerHTML = convertedData.name 
      price.innerHTML = convertedData.price 
      desc.innerHTML = convertedData.description
      enroll.innerHTML = `
          &lt;a id=&quot;enrollButton&quot; class=&quot;btn btn-success text-white btn-block&quot;&gt;Enroll&lt;/a&gt;
      `
  
      document.querySelector(&quot;#enrollButton&quot;).addEventListener(&quot;click&quot;, () =&gt; {
          
          fetch('http://localhost:4000/api/users/enroll', {
              method: 'POST',
              headers: {
                  'Content-Type': 'application/json',
                  'Authorization': `Bearer ${token}`//we have to get the actual value of the token value
              },
              body: JSON.stringify({
                  courseId: id
              })
          }).then(res =&gt; {
              return res.json()
          }).then(convertedResponse =&gt; {
              console.log(convertedResponse)
              if (convertedResponse === true) {
                  Swal.fire('Congratulations!',
                  `You have successfully enrolled to ${convertedData.name}!`,
                  'success')
              } else {
                  Swal.fire('Error!',
                  `Something went wrong!`,
                  'error')
              }
          })
          })
  })
  </code></pre>
  <p>What I'm trying to accomplish is to create a logic that will check if the subject is already enrolled. I already understand the logic however upon execution it's not working.</p>