{"version":"1.0","type":"rich","title":"MongoDB Aggregation Framework way for \"select count (distinct fieldName) from someTable\" for large collections","description":"This example shows how to compute the equivalent of a SQL “select count (distinct fieldName) from someTable” using MongoDB’s Aggregation Framework for large collections. The code uses the `db.someCollection.aggregate()` method with two `$group` stages: the first groups documents by the distinct value of `fieldName` (assigned to `_id`), and the second groups all results into a single document (`_id: 1`) while summing the number of groups with `$sum: 1` to produce the final count. The snippet is written as a JavaScript gist and relies solely on MongoDB’s native aggregation pipeline, with no external visualization library.","provider_name":"VizHub AI Studio","provider_url":"https://next.vizhub.com","html":"<iframe src=\"https://next.vizhub.com/viz/gist-ab43242745081d29421800568689d83a?mode=embed\" width=\"960\" height=\"500\" scrolling=\"no\" frameborder=\"1\"></iframe>","width":960,"height":500,"cache_age":3600}