Skip to content

Instantly share code, notes, and snippets.

@kishorek
Created October 12, 2023 13:24
Show Gist options
  • Save kishorek/417aef863868ae3f15d325a3880437ad to your computer and use it in GitHub Desktop.
Save kishorek/417aef863868ae3f15d325a3880437ad to your computer and use it in GitHub Desktop.
Mongo - Get distinct values of a field
[
{
$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