Skip to content

Implement $all operator for array subset matching #16

Description

@protobi-pieter

Implemented the $all operator to check if an array value contains all elements from a constraint array.

Use Case

Select records where an array field contains all specified values. For example, finding patients who have all of diabetes (3), obesity (5), and apnea (7):

Query.query(patients, {
  conditions: {$all: [3, 5, 7]}
})

Behavior

  • {x: [1,3,5,7]} with {x: {$all: [5,7]}} → TRUE (has both)
  • {x: [1,3,5]} with {x: {$all: [5,7]}} → FALSE (missing 7)
  • {x: []} with {x: {$all: []}} → TRUE (vacuous truth)
  • Scalar values treated as single-element arrays
  • Uses loose equality matching (e.g., "3" == 3)

Implementation

Follows MongoDB's $all operator semantics and the existing lhs:rhs pattern used throughout the library.

Implemented in commit 2c3936b

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions