I am using Wix code/Javascript to try and sum items in a database collection - the only issue is whomever initially set it up created the nos field as text instead of an integer.
For some reason I can perform a max aggregation on the database which returns a 1, however I cannot sum it. (returns 0)
The way I see it is I have two options:
Painstakingly create a new field with the correct data type for
nosand copy the data over and change all inputs for the field (less than keen on this idea due to it being a live database)Use a function possibly
$convert:to change the text value to an int to allow sum
My code is as below:
import wixData from 'wix-data';
import wixUsers from 'wix-users';
$w.onReady( function() {
const filter = wixData.filter().eq("_owner", "SomeHashedValue");
wixData.aggregate("CollectionName")
.filter(filter)
.group("_owner")
.sum("nos", "sumnos")
.run()
.then( (results) => {
console.log(results.items)
} )
} )
Anyone know if option 2 is possible or if there's a better way of doing it?
Note: I know I'm not using wix-users in the code but I will be, it's just easier for testing not to!