feat(NODE-7328): Add ignoreUndefined option to EJSON APIs#853
Merged
baileympearson merged 6 commits intomongodb:mainfrom Jan 22, 2026
Merged
Conversation
- Introduced `ignoreUndefined` option to `EJSON.stringify` to omit undefined values from the output. - Updated tests to cover various scenarios for the new option, including nested objects and arrays. - Ensured compatibility with existing options like `relaxed` and `replacer` functions.
baileympearson
requested changes
Dec 9, 2025
Contributor
baileympearson
left a comment
There was a problem hiding this comment.
Hi @ShtibsDev - thanks for this contribution! We agree that this makes sense.
I left a few small comments.
Introduce EJSONSerializeOptions and EJSONParseOptions to distinguish between serialization-only options (ignoreUndefined) and parse-only options (useBigInt64). EJSONOptions remains as the intersection for backward compatibility. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
baileympearson
requested changes
Jan 5, 2026
baileympearson
approved these changes
Jan 13, 2026
PavelSafronov
approved these changes
Jan 16, 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.
ignoreUndefinedoption toEJSON.stringifyto omit undefined values from the output.relaxedandreplacerfunctions.Description
Introduced
ignoreUndefinedoption toEJSON.stringifyto omit undefined values from the output.Summary of Changes
ignoreUndefinedoption toEJSON.stringifyto omit undefined values from the output.Notes for Reviewers
Currently, the
EJSON.stringifycan't emulate mongo's behavior in caseignoreUndefinedis set in theMongoClientconstructor.By adding this option, the
EJSON.stringifybecomes more flexible and allows this behavior.What is the motivation for this change?
Codebases using MongoClient's ignoreUndefined currently have no way to stringify objects with the same behaviour without manually removing undefined properties via a recursive function.
This new option will allow stringifying object while both keeping the EJSON behavior and the undefined omitting behaviour.
Release Highlight
EJSONnow supportsignoreUndefinedserializesupports an option,ignoreUndefined, which instructs the serializer to skip any keys whose values areundefined.This option has been added to EJSON:
This option defaults to
false.Double check the following
npm run check:lint)type(NODE-xxxx)[!]: descriptionfeat(NODE-1234)!: rewriting everything in coffeescript