I want to $match where a field of an array of objects is not equal to the _id

Hello @schach_schach,

The $match can’t allow checking the internal fields condition directly, you need to use $expr operator, $not and $in operator to match your condition,

db.collection.aggregate([
  {
    $match: {
      $expr: {
        $not: {
          $in: ["$_id", "$applications.firstTimeInstalled.refId"]
        }
      }
    }
  }
])

Playground

3 Likes