Set expression and array operators

As with most programming languages, set operations ignore duplicate entries and the order of elements, treating them as sets. The order of results is unspecified and duplicates will be deduplicated in the result set. Set expressions do not apply recursively to elements of the set, but only to the top level. This means that if a set contains, for example, a nested array, then this array may or may not contain duplicates.

The available set operators are as follows:

  • $setEqualsThis is true if the two sets have the same distinct elements
  • $setIntersection: This returns the intersection of all input sets (that is, the documents that appear in all of the input sets)
  • $setUnion: This returns the union of all input sets (that is, the documents that appear in at least one of all of the input sets)
  • $setDifference: This returns the documents that appear in the first input set but not the second
  • $setIsSubset: This is true if all documents in the first set appear in the second one, even if the two sets are identical
  • $anyElementTrue: This is true if any of the elements in the set evaluate to true
  • $allElementsTrue: This is true if all of the elements in the set evaluate to true

The available array operators are as follows:

  • $arrayElemAt: This returns the element at the array index position.
  • $concatArrays: This returns a concatenated array.
  • $filter: This returns a subset of the array based on specified criteria.
  • $indexOfArray: This returns the index of the array that fulfills the search criteria. If it does not, then -1.
  • $isArray: This returns true if the input is an array; otherwise, it returns false.
  • $range: This outputs an array containing a sequence of integers according to user-defined inputs.
  • $reverseArray: This returns an array with the elements in reverse order.
  • $reduce: This reduces the elements of an array to a single value according to the specified input.
  • $size: This returns the number of items in the array.
  • $slice: This returns a subset of the array.
  • $zip: This returns a merged array.
  • $in: This returns true if the specified value is in the array; otherwise, it returns false.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset