feat(mongodb-constants): add $$IDX system variable for MongoDB 8.3 MONGOSH-3244#817
Merged
Conversation
…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.
mabaasit
approved these changes
Jul 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
$$IDXtoSYSTEM_VARIABLESinmongodb-constants, version-gated to MongoDB 8.3+. It exposes the index of the current array element in$map,$filter, and$reduceexpressions. Users can usearrayIndexAsto assign a custom name instead.filter.spec.tsverifying$$IDXexists with the correct version and meta, and that it is included/excluded based on server version.autocompleter.spec.tsverifyingarrayIndexAsis suggested for all three operators.Notes on the autocomplete test
$filterrequires the prefixarrayInrather thanarrayto reliably surfacearrayIndexAs. With the shorterarrayprefix, 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.$mapand$reduceare not affected and work with thearrayprefix.Test plan
mongodb-constants— 123 tests passingmongodb-ts-autocomplete— 12 tests passing (including newarrayIndexAstest)