min( )
Refines a WixDataAggregate
to only contain the minimum value from each aggregation group.
Description
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, 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"
, wherepropertyName
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.
Syntax
function min(propertyName: string, [projectedName: string]): WixDataAggregate
min Parameters
NAME
TYPE
DESCRIPTION
The property in which to find the minimum value.
The name of the property in the aggregation results containing the minimum value.
Was this helpful?
1let newAggregate = aggregate.min("population");
1let newAggregate = aggregate.min("population", "minPopulation");
1import wixData from 'wix-data';23// ...45wixData.aggregate("PopulationData")6 .group("state", "year")7 .min("population")8 .run()9 .then((results) => {10 if (results.items.length > 0) {11 let items = results.items; // see below12 let numItems = results.length; // 613 let hasNext = results.hasNext(); // false14 } else {15 // handle case where no matching items found16 }17 })18 .catch((error) => {19 let errorMsg = error.message;20 let code = error.code;21 });2223/* Given the sample data above, items is:24 * [25 * {26 * "_id": {"state": "NY", "year": 2000},27 * "populationMin": 292000,28 * "state": "NY",29 * "year":200030 * },31 * {32 * "_id": {"state": "FL", "year": 2000},33 * "populationMin": 195000,34 * "state": "FL",35 * "year":200036 * },37 * {38 * "_id": {"state": "NY", "year": 2010},39 * "populationMin": 261000,40 * "state": "NY",41 * "year":201042 * },43 * {44 * "_id": {"state": "CA", "year": 2010},45 * "populationMin": 805000,46 * "state": "CA",47 * "year":201048 * },49 * {50 * "_id": {"state": "CA", "year": 2000},51 * "populationMin": 777000,52 * "state": "CA",53 * "year":200054 * },55 * {56 * "_id": {"state": "FL", "year": 2010},57 * "populationMin": 240000,58 * "state": "FL",59 * "year":201060 * }61 * ]62 */
1import wixData from 'wix-data';23// ...45wixData.aggregate("PopulationData")6 .group("state", "year")7 .min("population", "minimumPopulation")8 .run()9 .then((results) => {10 if (results.items.length > 0) {11 let items = results.items; // see below12 let numItems = results.length; // 613 let hasNext = results.hasNext(); // false14 } else {15 // handle case where no matching items found16 }17 })18 .catch((error) => {19 let errorMsg = error.message;20 let code = error.code;21 });2223/* Given the sample data above, items is:24 * [25 * {26 * "_id": {"state": "NY", "year": 2000},27 * "minimumPopulation": 292000,28 * "state": "NY",29 * "year":200030 * },31 * {32 * "_id": {"state": "FL", "year": 2000},33 * "minimumPopulation": 195000,34 * "state": "FL",35 * "year":200036 * },37 * {38 * "_id": {"state": "NY", "year": 2010},39 * "minimumPopulation": 261000,40 * "state": "NY",41 * "year":201042 * },43 * {44 * "_id": {"state": "CA", "year": 2010},45 * "minimumPopulation": 805000,46 * "state": "CA",47 * "year":201048 * },49 * {50 * "_id": {"state": "CA", "year": 2000},51 * "minimumPopulation": 777000,52 * "state": "CA",53 * "year":200054 * },55 * {56 * "_id": {"state": "FL", "year": 2010},57 * "minimumPopulation": 240000,58 * "state": "FL",59 * "year":201060 * }61 * ]62 */