Check out this NEW RELATED QUESTION:
I need to extract the largest number from a given object set.
I am struggling with finding a solution. I have tried using max but I think my skills are lacking. Here is the code I have so far:
@Function()
public async largestNumber(): Promise<Long> {
const objResult = Objects.search()
.dataMain()
.filter(data_column => data_column.lngPlanningNumber.range. )
.gt(100)
.take(1);
return objResult.max();
}
This function currently retrieves objects with NULL values for the lngPlanningNumber
property, which I want to exclude.
UPDATE:
Property 'isNotNull' does not exist on type 'INumericPropertyFilter'.
for
.filter(data_column => data_column.lngPlanningNumber.isNotNull()) // filter out NULL values
Property 'take' does not exist on type 'Promise<number | null>'.
for
.take(1);
NEW RELATED QUESTION: my code
@Function()
@Edits(XYZ)
public async fctLargestNumber(): Promise<XYZ[]> {
const maxObject = Objects.search()
.xYZ()
// .groupBy(e => e.lngPlanningNumber.topValues())
// .segmentBy(e => e.lngPlanningNumber.topValues())
// .filter(data_column => data_column.lngPlanningNumber.byIRanges({ min: 100000, max: 999999 }))
.orderBy(data_column => data_column.lngPlanningNumber.desc())
.takeAsync(1)
//.valueOf();
return maxObject;
now I am getting an output like this:
[
{"typeId":"my-collection","primaryKey":{"id_pk":"ee1b1ac1-008b-479b-a748-01e8702927c9"}}
]
The challenge now is how to retrieve my desired result.
- How can I extract the primary key value?
- How do I locate the requested integer value of column "lngPlanningNumber" associated with this id?
The Promise aspect intrigues me. Thank you