MongoDB Set Operators

MongoDB set operators are a group of special operators used to manipulate collection-type fields, including set union, set difference, set intersection, etc. They can be used for various operations on sets in both aggregation queries and regular queries. This page lists the set operators available in MongoDB.

  1. $allElementsTrue

    $allElementsTrue is a logical operator in MongoDB used to test whether all elements in an array field are true.
  2. $anyElementTrue

    $anyElementTrue is an operator in MongoDB’s query language used to match array fields that contain at least one element that is true.
  3. $setDifference

    The MongoDB $setDifference operator is one useful operator that is used to get the different elements between two collections.
  4. $setEquals

    $setEquals is a set operator in MongoDB that can be used to compare whether two sets are equal.
  5. $setIntersection

    $setIntersection is an array operator in MongoDB that returns the intersection of two arrays.
  6. $setIsSubset

    $setIsSubset operator is an array operator in MongoDB, used to determine if an array is a subset of another array, and returns a Boolean value.
  7. $setUnion

    $setUnion is an aggregation operator in MongoDB that merges two arrays into a single array and removes duplicates.