Created
October 12, 2023 13:24
-
-
Save kishorek/417aef863868ae3f15d325a3880437ad to your computer and use it in GitHub Desktop.
Mongo - Get distinct values of a field
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
[ | |
{ | |
$unwind: { | |
path: '$field_name', | |
preserveNullAndEmptyArrays: true | |
} | |
}, | |
{ | |
$group: { | |
_id: null, | |
uniqueGenres: { $addToSet: '$field_name' } | |
} | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment