Last active
August 5, 2019 20:24
-
-
Save FlavienBusseuil/cd35e75cfffe5d8d8c97606bafdd21e9 to your computer and use it in GitHub Desktop.
Conditional Array Initialization
This file contains 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
/* Start initializing aggregation stages based on condition */ | |
const aggregationStages = [ | |
stage1, | |
stage2, | |
]; | |
if (condition) { | |
aggregationStages.push(stage3); | |
} | |
aggregationStages.push(stage4); | |
/* Initialization ended */ | |
db.collection.aggregate(aggregationStages); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment