SetFilter does not exist on database1

I need to filter my dataset to the e-mail of the logged in user:

import wixData from ‘wix-data’;
import wixUsers from ‘wix-users’;
$w.onReady( function () {
let user = wixUsers.currentUser;
let customers = user.getEmail()
let userEmail = customers;
$w(“#dataset1”).setFilter( wixData.filter()
.eq(“title”, userEmail) );
});

But I get the error that setFilter does not exist on dataset1. What does it mean? Can somebody help me.

Michael

What is the id of the dataset you have added to your page? It must be dataset1 for that to work. Check that first.

That is the next problem: I can not see the dataset element on that page nor can I open any database or create any new collection. So I have no sandbox view nor the dataset element on the page. I see the repeater connected to the database but no dataset element shows.

Michael

@triplegrace55 On your page you should have the below Dataset added. Make sure you have gone to the menu in the Wix Editor and Enabled Developer Tools under the Code menu item.

I have done that but the dataset element does not show up but the repeater element is connected to the database. I added it but now I can not see it anymore.

Michael

Have you hidden it? Try in the menu to make sure you show hidden elements. Look behind other elements. It must be on the page if you can use it in the repeater. Please take a screenshot of the page and the repeater data connection settings.

Already done. Nothing shows up.

Michael

Ok so next step is that you screenshot as much as you can and give to us here so we can investigate more in details.

The screenshots:

And now when I click on my collection “Ranking” nothing happens when actually the Sandbox should appear:

Michael

Noch einer:

It shall look like this:

Why is it that I can not see the dataset element or the sandbox of my collection “Ranking”??

Michael

I found the dataset, it was dataset1 and now there is no mistake in the code but still not working. In the collection database which format is required for an email field: text, rich text, number or?

Is the code correct?

import wixData from ‘wix-data’; import wixUsers from ‘wix-users’; $w.onReady( function () { let user = wixUsers.currentUser; let customers = user.getEmail() let userEmail = customers; $w(" #dataset1 ").setFilter( wixData.filter() .eq(“title”, userEmail) ); });

Michael

If I use $w(“#dataset1”).setFilter( wixData.filter() .eq(“title”, “example@gmail.com”) ); it is working but if I use .eq(“title”, userEmail) ); then it is not working. Can somebody please check the code? Thank you.

Michael

Hey
To get a users email you must do the below

let user = wixUsers.currentUser;

let userId = user.id;           // "r5cme-6fem-485j-djre-4844c49"
let isLoggedIn = user.loggedIn; // true

user.getEmail()
  .then( (email) => {
    let userEmail = email;      // "user@something.com"
    $w("#dataset1").setFilter( wixData.filter()
    .eq("title", userEmail) );
  } );

getEmail returns a promise that needs to be resolved and inside that .then you can then use the setFilter.

@andreas-kviby Thank you so much. Now all works fine.
Thanks again.

Michael

@triplegrace55 Please mark my answer as TOP COMMENT as it will help others find the solution