Wix equivalent of the WHERE clause

I have an array which I want to store in a DB field called ‘subject’. The ‘subject’ field must be the one belonging to the current user. I want to use the user’s email as an identifier to do this (also the primary key in the DB.) The following code will be executed on a button click and it all occurs from a lightbox.

Is the following correct?

let user = wixUsers.currentUser;
user.getEmail().then( (email) => {
userEmail = email;
} );
let academ = local.getItem(“academChecked”);
console.log(academ);

const toInsert = {
“subject”:academ
};

wixData.query(“TeacherDetails”)
.eq(“email”, userEmail)
.find()
.then( (results) => {
wixData.insert(“TeacherDetails”, toInsert);
} )
.catch( (error) => {
let errorMsg = error.message;
let code = error.code;
} );

Hi,
Your script seems to be good. One remark though; the userEmail isn’t accessible from outside the user.getEmail().then( (email) => {} function.If you’ll put the rest of the script inside the braces it should work.

Best Regards,
Dima