Cara menggunakan mongodb count distinct aggregation
For the legacy 6 shell documentation, refer to the documentation for the corresponding MongoDB Server release: Show
Finds the distinct values for a specified field across a single collection or view and returns the results in an array. This method takes the following parameters: Parameter Type Description
string The field for which to return distinct values.
document A query that specifies the documents from which to retrieve the distinct values.
document Optional. A document that specifies the options. See NoteResults must not be larger than the maximum . If your results exceed the maximum BSON size, use the aggregation pipeline to retrieve distinct values using the operator, as described in The following diagram shows an example call. Options
Field Type Description
document Optional. Specifies the to use for the operation. Collation allows users to specify language-specific rules for string comparison, such as rules for lettercase and accent marks. Aggregation operations process multiple documents and return computed results. You can use aggregation operations to: Group values from multiple documents together. Perform operations on the grouped data to return a single result. Analyze data changes over time. To perform aggregation operations, you can use: , which are simple but lack the capabilities of an aggregation pipeline. An aggregation pipeline consists of one or more that process documents: Each stage performs an operation on the input documents. For example, a stage can filter documents, group documents, and calculate values. The documents that are output from a stage are passed to the next stage. An aggregation pipeline can return results for groups of documents. For example, return the total, average, maximum, and minimum values. Starting in MongoDB 4.2, you can update documents with an aggregation pipeline if you use the stages shown in Updates with Aggregation Pipeline. NoteAggregation pipelines run with the method do not modify documents in a collection, unless the pipeline contains a or stage. Aggregation Pipeline ExampleThe following aggregation pipeline example contains two and returns the total order quantity of medium size pizzas grouped by pizza name:
The stage:
The stage:
For runnable examples containing sample input documents, see Learn More About Aggregation PipelinesTo learn more about aggregation pipelines, see Single Purpose Aggregation MethodsThe single purpose aggregation methods aggregate documents from a single collection. The methods are simple but lack the capabilities of an aggregation pipeline. |