title: MongoDB compare arrays
body: <p>I have a collection with thousands of users. Each user document has a few properties like name, age range, and favourites.</p>
  
  <p>I can easily help users find other users that are the within the same age range but I also want to somehow allow them to choose a matching percentage OR number  of the favourites they have in common with other users.</p>
  
  <p>Eg.</p>
  
  <pre><code>User 1
  Name: x
  Age Range: 19-25
  Favourites: ["Red", "Green", "Blue"]
  
  User 2
  Name: y
  Age Range: 19-25
  Favourites: ["Orange", "Red", "Pink"]
  
  User 3
  Name: z
  Age Range: 19-25
  Favourites: ["Orange", "Red", "Blue"]
  </code></pre>
  
  <p>Here, if user 1 searched for users with a 33% match OR at least one common match, they would get only user 2. If they searched for a 66% OR at least two common matches, they would get user 3.</p>
  
  <p>I've done the easy part and matched by age range and tried to work with mongoDB <code>$all</code> and <code>$in</code> but it's not exactly what I'm looking for. Can someone point me in the right direction?</p>