Fetching specific data based on users email address

I have a dataset named Files with four columns (student email address, Assignment Submissions Link, Digital Badges Link, Lesson Files Link). I am trying to connect these links to button on my site. It is an educational site and I need a way for students to send me files through a dropbox link.

My goal is to fetch data from my dataset that matches the users email but it will not work for some reason. Take a look and let me know if you see anything wrong with my code.

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

export function button9_click(event) {
// This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center | Wix.com
// Add your code for this event here:

let user = wixUsers.currentUser;
// let query = wixData.query(“Files”);

if (user){

    user.getEmail() 
    .then( (email) => { 
	**let**  userEmail = email;       // "user@something.com" 
	**return**  userEmail; 
    } ) 
    .then( (userEmail) => { 

        wixData.query( "Files" ) 
        .eq( "email" , userEmail) 
        .find() 
        .then( (results) => { 
            console.log(results.totalCount); 
        } ); 

    } ); 
} 

}

Are you sure the field key is “email” and not “studentEmailAddress” ?

The Field Name is “Student Email Address” and the field key is “studentEmailAddress”. Both give me 0 entries when I try to fetch.


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

export function button9_click(event) {
// This function was added from the Properties & Events panel. To learn more, visit Velo: Working with the Properties & Events Panel | Help Center | Wix.com
// Add your code for this event here:

let user = wixUsers.currentUser;
// let query = wixData.query(“Files”);

if (user){

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

let userEmail = email; // “user@something.com
return userEmail;
} )
.then( (userEmail) => {

        wixData.query( "Files" ) 
        .eq( "studentEmailAddress" , userEmail) 
        .find() 
        .then( (results) => { 
            console.log(results.totalCount); 
        } ); 

    } ); 
} 

}

@financialacademyca it can be many thing.

  1. Make sure you’re logged in

  2. Make sure your email appears in the collection (without extra spaces).

  3. Check your collection permission.

  4. Sync sandbox with live site.

  5. Also it’s a better practice to chain promises and not to net them so:

import wixLocation from 'wix-location';
import wixUsers from 'wix-users';
import wixData from 'wix-data';

export function button9_click(event) {
 let user = wixUsers.currentUser;
 if(user){
        user.getEmail()
        .then(email => {
            return wixData.query("Files")
            .eq("studentEmailAddress", email)
            .find();
        })
.	.then( (results) => {
                console.log(results.totalCount);
            } );
    }
}