i m trying to add new database entry of loggedin user!help

import wixUsers from ‘wix-users’;
import wixData from ‘wix-data’;
import wixLocation from ‘wix-location’;
if (wixUsers.currentUser.loggedIn) {
let user = wixUsers.currentUser;
let userEmail
let userId = user.id; // “r5cme-6fem-485j-djre-4844c49”
let isLoggedIn = user.loggedIn; // true
let userRole = user.role; // “Member”

     user.getEmail() 
    .then( (email) => { 

// check if there is an item for the user in the collection
userEmail = email;
return wixData.query(“Profile”)
.eq(“_id”, userId)
.find();
} ) .then( (results) => {
// if an item for the user is not found
if (results.items.length === 0) {
// create an item
const toInsert = {
“_id”: userId,
“email”: userEmail
};
// add the item to the collection
wixData.insert(“Profile”, toInsert)
. catch ( (err) => {
console.log(err);
});

    } 
  }

Hello Milind,

would you please explain more what the problem is ?

Massa