Set expression and array operators

Set expressions perform set operations on arrays, treating arrays as sets. Set expressions ignores duplicate entries in each input array and the order of the elements.

If the set operation returns a set, the operation filters out duplicates in the result to output an array that contains only unique entries. The order of the elements in the output array is unspecified. If a set contains a nested array element, the set expression does not descend into the nested array but evaluates the array at top-level.

The available set operators are:

  • $setEqualsThis is true if the two sets have the same distinct elements
  • $setIntersection: This returns the intersection (documents that appear in all) of all input sets
  • $setUnion: This returns the union (documents that appear in at least one) of all 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:

  • $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 not, -1
  • $isArray: This returns true if the input is an array; otherwise, 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 the opposite 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 false
..................Content has been hidden....................

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