> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: min(propertyName: string, projectedName: string) # Method package: wixData # Method menu location: wixData --> WixDataAggregate --> min # Method Link: https://dev.wix.com/docs/velo/apis/wix-data/wix-data-aggregate/min.md # Method Description: Refines a `WixDataAggregate` to only contain the minimum value from each aggregation group. The `min()` function refines a `WixDataAggregate` to contain the minimum value from the specified property for each aggregated group or from the whole collection if no group is defined. When the aggregation is [run](#run), the returned `WixDataAggregateResult` object contains an item for each group with the following `key:value` pairs: + If a value was passed for the optional `projectedName`, the key is named using that value. Otherwise, the key is named using the following format: `"propertyNameMin"`, where `propertyName` is the name of the specified property. + The value is the minimum value found in the specified property. The following types of properties can be compared to determine a minimum value: + Number: Compares numerically. + Date and Time: Compares JavaScript Date objects. + Text: Compares lexicographically, so `"text"` is greater than `"Text"`. + Rich Text: Compares HTML source as text. + URL: Compares as text. + Image: Compares image source as text. + Video: Compares video source as text. + Document: Compares document source as text. + Reference: Compares by the ID of the referenced item as a String. > **Note:** Aggregations can only be used on collections you have created. They cannot be used on [Wix App Collections](https://support.wix.com/en/article/cms-formerly-content-manager-working-with-wix-app-collections). # Method Code Examples: *** Note: do not assume any prop names or enum values other than the ones in the example. ## Add a min aggregation ```javascript let newAggregate = aggregate.min("population"); ``` ## Add a min aggregation with a projected name for the results ```javascript let newAggregate = aggregate.min("population", "minPopulation"); ``` ## Create an aggregation, add a max aggregation, and run it ```javascript import wixData from 'wix-data'; // ... wixData.aggregate("PopulationData") .group("state", "year") .min("population") .run() .then((results) => { if (results.items.length > 0) { let items = results.items; // see below let numItems = results.length; // 6 let hasNext = results.hasNext(); // false } else { // handle case where no matching items found } }) .catch((error) => { let errorMsg = error.message; let code = error.code; }); /* Given the sample data above, items is: * [ * { * "_id": {"state": "NY", "year": 2000}, * "populationMin": 292000, * "state": "NY", * "year":2000 * }, * { * "_id": {"state": "FL", "year": 2000}, * "populationMin": 195000, * "state": "FL", * "year":2000 * }, * { * "_id": {"state": "NY", "year": 2010}, * "populationMin": 261000, * "state": "NY", * "year":2010 * }, * { * "_id": {"state": "CA", "year": 2010}, * "populationMin": 805000, * "state": "CA", * "year":2010 * }, * { * "_id": {"state": "CA", "year": 2000}, * "populationMin": 777000, * "state": "CA", * "year":2000 * }, * { * "_id": {"state": "FL", "year": 2010}, * "populationMin": 240000, * "state": "FL", * "year":2010 * } * ] */ ``` ## Create an aggregation, add a min aggregation with a projected name for the results, and run it ```javascript import wixData from 'wix-data'; // ... wixData.aggregate("PopulationData") .group("state", "year") .min("population", "minimumPopulation") .run() .then((results) => { if (results.items.length > 0) { let items = results.items; // see below let numItems = results.length; // 6 let hasNext = results.hasNext(); // false } else { // handle case where no matching items found } }) .catch((error) => { let errorMsg = error.message; let code = error.code; }); /* Given the sample data above, items is: * [ * { * "_id": {"state": "NY", "year": 2000}, * "minimumPopulation": 292000, * "state": "NY", * "year":2000 * }, * { * "_id": {"state": "FL", "year": 2000}, * "minimumPopulation": 195000, * "state": "FL", * "year":2000 * }, * { * "_id": {"state": "NY", "year": 2010}, * "minimumPopulation": 261000, * "state": "NY", * "year":2010 * }, * { * "_id": {"state": "CA", "year": 2010}, * "minimumPopulation": 805000, * "state": "CA", * "year":2010 * }, * { * "_id": {"state": "CA", "year": 2000}, * "minimumPopulation": 777000, * "state": "CA", * "year":2000 * }, * { * "_id": {"state": "FL", "year": 2010}, * "minimumPopulation": 240000, * "state": "FL", * "year":2010 * } * ] */ ``` ---