Skip to content

feat(mongodb-constants): add $$IDX system variable for MongoDB 8.3 MONGOSH-3244#817

Merged
ivandevp merged 1 commit into
mainfrom
MONGOSH-3244-idx-variable
Jul 7, 2026
Merged

feat(mongodb-constants): add $$IDX system variable for MongoDB 8.3 MONGOSH-3244#817
ivandevp merged 1 commit into
mainfrom
MONGOSH-3244-idx-variable

Conversation

@ivandevp

@ivandevp ivandevp commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Adds $$IDX to SYSTEM_VARIABLES in mongodb-constants, version-gated to MongoDB 8.3+. It exposes the index of the current array element in $map, $filter, and $reduce expressions. Users can use arrayIndexAs to assign a custom name instead.
  • Adds two tests to filter.spec.ts verifying $$IDX exists with the correct version and meta, and that it is included/excluded based on server version.
  • Adds an integration test to autocompleter.spec.ts verifying arrayIndexAs is suggested for all three operators.

Notes on the autocomplete test

$filter requires the prefix arrayIn rather than array to reliably surface arrayIndexAs. With the shorter array prefix, TypeScript resolves JavaScript built-ins (Array, ArrayBuffer) ahead of the operator-specific field due to a known inference limitation with $filter's recursive generic type signature. $map and $reduce are not affected and work with the array prefix.

Test plan

  • mongodb-constants — 123 tests passing
  • mongodb-ts-autocomplete — 12 tests passing (including new arrayIndexAs test)

…NGOSH-3244

Adds the $$IDX system variable introduced in MongoDB 8.3, which exposes
the index of the current element in $map, $filter, and $reduce expressions.
Users can use arrayIndexAs to assign a custom name instead.

Also adds an integration test verifying arrayIndexAs is suggested by the
TS-based autocompleter for all three operators. Note: $filter requires the
prefix 'arrayIn' rather than 'array' to avoid TypeScript resolving JavaScript
built-ins (Array, ArrayBuffer) ahead of the operator-specific field — a known
TypeScript inference limitation with $filter's recursive generic type.
@ivandevp
ivandevp merged commit b1ec682 into main Jul 7, 2026
8 checks passed
@ivandevp
ivandevp deleted the MONGOSH-3244-idx-variable branch July 7, 2026 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants