Skip to content

feat(NODE-7328): Add ignoreUndefined option to EJSON APIs#853

Merged
baileympearson merged 6 commits intomongodb:mainfrom
ShtibsDev:feature/ignore-undefined-stringify
Jan 22, 2026
Merged

feat(NODE-7328): Add ignoreUndefined option to EJSON APIs#853
baileympearson merged 6 commits intomongodb:mainfrom
ShtibsDev:feature/ignore-undefined-stringify

Conversation

@ShtibsDev
Copy link
Contributor

@ShtibsDev ShtibsDev commented Nov 29, 2025

  • 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.

Description

Introduced ignoreUndefined option to EJSON.stringify to omit undefined values from the output.

Summary of Changes

  • 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.
Notes for Reviewers

Currently, the EJSON.stringify can't emulate mongo's behavior in case ignoreUndefined is set in the MongoClient constructor.

By adding this option, the EJSON.stringify becomes 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

EJSON now supports ignoreUndefined

serialize supports an option, ignoreUndefined, which instructs the serializer to skip any keys whose values are undefined.

This option has been added to EJSON:

> EJSON.stringify({ a: undefined }, { ignoreUndefined: true });
'{}'
> EJSON.stringify({ a: undefined }, { ignoreUndefined: false });
'{"a":null}'
> EJSON.serialize({ a: undefined }, { ignoreUndefined: true });
{}
> EJSON.serialize({ a: undefined }, { ignoreUndefined: false });
{ a: null }

This option defaults to false.

Double check the following

  • Lint is passing (npm run check:lint)
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

- 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.
@ShtibsDev ShtibsDev requested a review from a team as a code owner November 29, 2025 14:19
@dariakp dariakp changed the title feat(EJSON): Add ignoreUndefined option to EJSON serialization feat(NODE-7328): Add ignoreUndefined option to EJSON serialization Dec 1, 2025
@baileympearson baileympearson self-assigned this Dec 9, 2025
@baileympearson baileympearson added Primary Review In Review with primary reviewer, not yet ready for team's eyes External Submission labels Dec 9, 2025
Copy link
Contributor

@baileympearson baileympearson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ShtibsDev - thanks for this contribution! We agree that this makes sense.

I left a few small comments.

ofir-shtibs and others added 2 commits December 13, 2025 00:06
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 baileympearson added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Jan 13, 2026
@baileympearson baileympearson changed the title feat(NODE-7328): Add ignoreUndefined option to EJSON serialization feat(NODE-7328): Add ignoreUndefined option to EJSON APIs Jan 13, 2026
@dariakp dariakp requested a review from a team January 16, 2026 16:05
@baileympearson baileympearson merged commit 5cf00c2 into mongodb:main Jan 22, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants