Filter by user email then aggregate the result (Solved)

I changed to reference ID instead of email, and changed the code as follows. Then it works :

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;

let user = wixUsers.currentUser;
let userId = user.id;
user.getEmail()
.then( (email) => {
let userEmail = email;

} );

$w.onReady(() => {
Sum_pointsSpend();

});

export function Sum_pointsSpend() {

let filter = wixData.filter().eq(“title”, userId);
// In PointsHistory dataset the “title” column value is from privatememberdata userId field)
console.log(filter); // This is to help you figure out if the wanted item had been filtered out
wixData.aggregate(“PointsHistory”)
.filter(filter)
.sum(“pointsSpend”, “sumpointsSpend”)
.run()
.then( (results) => {

        $w('#TP').value = results.items[0].sumpointsSpend;  // TP is the text box showing sum 
    console.log(results);    

} );
}

#filter #Aggregate