title: How to check if there is a document with this value in React + MongoDB?
body: <p>So I am building a MERN movie app. There is a collection with movies ratings by users. When opening an individual movie page I want to be able to check if this movie was already rated by the current user.</p>
  <p>All I came up with for now is to get all the movies rated by the user and to check if this array has an object with this movie's <code>id</code> using <code>useEffect</code> and <code>useState</code>.</p>
  <pre><code>  const [isRated, setIsRated] = useState(false)
  
    useEffect(() =&gt; {
      if (rated.filter((rated) =&gt; rated.movieId === data?.id).length !== 0) setIsRated(true)
    }, [rated, data?.id])
  </code></pre>
  <p>It works for rated movies, but when I am clicking on a link to another movie and the page's content rerenders, the <code>isRated</code> remains true for some reason even if it is not rated and it causes a problem.</p>
  <p>What are better ways to do this without having to refresh the page each time? I am new to backend so any advise would be aprreciated.</p>
  <p>Thanks in advance.</p>