title: MongoDB - find() with 5 filters and conditions gives different results than no conditions
body: <p>I'm wrote and tested a query to retrieve the documents and it works just fine it gets exactly what I asked for and when I take out each of the filters it retrieves the corrent documents. Now instead of manually commenting each filter I want to base it on the index as it goes down, so at <code>index = 4</code> it should use all filters and at <code>index = 3</code> it should use one less filter until at <code>index = 0</code> where it should just get the documents.</p>
  <p>The code that works just fine:</p>
  <pre><code>    users = await User.find({
        $and: ignoreUsers.map((id) =&gt; {
          return { _id: { $ne: new ObjectId(id) } };
        }),
        objectives: { $in: objectives },
        ranking: ranking,
        expLevel: { $gte: expLevel - 1, $lte: expLevel + 1 },
        industries: { $in: industries },
        &quot;skills.self&quot;: { $in: skills },
        interests: { $in: interests },
      });
  </code></pre>
  <p>This produces 1 document which is correct, however when I add the if conditions it produces 5 documents which is not corrent. The <code>ranking.&lt;variable&gt;</code> are numbers 1-4 so if the <code>index = 4</code> then all the if conditions should be true right? but none of them are being executed. only the objectives and ranking filters work, the whole <code>$expr</code> conditions are being ignored</p>
  <pre><code>        let index = 4;
  
          // supposed to be in while loop but testing just once does not produce just the 1 document it's supposed to
  
          const fetchCondUsers = await User.find({
            $and: ignoreUsers.map((id) =&gt; {
              return { _id: { $ne: new ObjectId(id) } };
            }),
            objectives: { $in: objectives },
            
            $expr: {
              $cond: {
                if: { $gte: [index, 0] },
                then: {
                  ranking: ranking,
                },
                else: &quot;$$REMOVE&quot;,
              },
              $cond: {
                if: { $gte: [index, ranking.expLevel] },
                then: {
                  $and: [
                    { $gte: [&quot;$expLevel&quot;, expLevel - 1] },
                    { $lte: [&quot;$expLevel&quot;, expLevel + 1] },
                  ],
                },
                else: &quot;$$REMOVE&quot;,
              },
              $cond: {
                if: { $gte: [index, ranking.industry] },
                then: {
                  industries: { $in: [&quot;$industries&quot;, industries] },
                },
                else: &quot;$$REMOVE&quot;,
              },
              $cond: {
                if: { $gte: [index, ranking.skills] },
                then: {
                  skills: { $in: [&quot;$skills&quot;, skills] },
                },
                else: &quot;$$REMOVE&quot;,
              },
              $cond: {
                if: { $gte: [index, ranking.interests] },
                then: {
                  interests: { $in: [&quot;$interests&quot;, interests] },
                },
                else: &quot;$$REMOVE&quot;,
              },
            },
          }).limit(limit);
  </code></pre>
  <p>Ideally this is what I'm trying to do</p>
  <pre><code>      users = await User.find({
          $and: ignoreUsers.map((id) =&gt; {
            return { _id: { $ne: new ObjectId(id) } };
          }),
          objectives: { $in: objectives },
          if (index === 0) ranking: ranking,
          if (index === 1) expLevel: { $gte: expLevel - 1, $lte: expLevel + 1 },
          if (index === 2) industries: { $in: industries },
          if (index === 3) &quot;skills.self&quot;: { $in: skills },
          if (index === 4) interests: { $in: interests },
        });
  </code></pre>