Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FlavienBusseuil/481f1be507db004c60cb125cf6916ccd to your computer and use it in GitHub Desktop.
Save FlavienBusseuil/481f1be507db004c60cb125cf6916ccd to your computer and use it in GitHub Desktop.
Inline Conditional Object Initialization with Spread Operator
const filters = {
filter1,
filter2,
...(condition && { filter3 }),
filter4,
};
db.collection.find(filters);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment