# Filtering a Dataset by User (NOT Owner)

**URL:** <https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772>\
**Category:** Ask the community\
**Tags:** wix-members-area, code, question\
**Created:** [January 5, 2019, 9:32am UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772 "2019-01-05T09:32:55Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![scottewingdesign](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/scottewingdesign/32/6044_2.png) [@scottewingdesign](https://forum.wixstudio.com/u/scottewingdesign)\
**Post date:** [January 5, 2019, 9:32am UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/1 "2019-01-05T09:32:55Z")

</div>

Hi all,

I’m having a little trouble with something that I’m trying to do.

I currently have a database containing a list of vehicles owned by my site’s members. I will be managing and updating the data personally, so all records have my user id in the Owner field.

I would like to have a list in the members area of my site which shows a user all of THEIR vehicles, however because I am the owner of all the records I can’t simply filter by Logged in User on the Owner column.

My solution to this was to have an email address column in the database and filter by that, however my attempts at fetching the currently logged in user’s email all failed - I’m not sure if I understand how to use the APIs. If somebody could please explain the process to get the user’s email address and then use that address to filter a dataset, that would be extremely helpful.

Alternatively, is there another way that I could go about filtering these results? I’m open to any ideas.

Thanks very much,

Scott

---

<div class="post-metadata">

**Author:** ![sapirh](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/sapirh/32/6655_2.png) [@sapirh](https://forum.wixstudio.com/u/sapirh)\
**Post date:** [January 6, 2019, 11:57am UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/2 "2019-01-06T11:57:25Z")

</div>

Hi Scott,

This how the function getEmail() suppose to be:

```javascript

import wixUsers from 'wix-users';

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

```

I suggest you to add this method to the onReady() function of the member area page. This function runs before the user starts interacting with your page.

If you still have a problem, please send us a URL to your site and specify the name of the page.

Best,  
Sapir

---

<div class="post-metadata">

**Author:** ![scottewingdesign](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/scottewingdesign/32/6044_2.png) [@scottewingdesign](https://forum.wixstudio.com/u/scottewingdesign)\
**Post date:** [January 6, 2019, 9:52pm UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/3 "2019-01-06T21:52:08Z")

</div>

Hi Sapir, thanks very much for your reply. I swear that I had tried that exact code previously and kept getting an error about an unhandled promise in the console, but when I typed it in this time it seemed to work fine.

Now that I think I have the email address, I’m trying to filter my dataset with the code below, but that doesn’t seem to be working. clearly I’m missing something.

**import** wixUsers **from** ‘wix-users’;  
**import** wixData **from** ‘wix-data’;

$w.onReady( **function** () {  
//TODO: write your page related code here…  
wixUsers.currentUser.getEmail()  
.then( (email) =\> {  
**let** userEmail = email; //"user@something.com"  
})

```
$w("#myVehiclesSet").setFilter(wixData.filter() 
    .eq("vehicle_user", wixUsers.userEmail)) 

```

});

---

<div class="post-metadata">

**Author:** ![scottewingdesign](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/scottewingdesign/32/6044_2.png) [@scottewingdesign](https://forum.wixstudio.com/u/scottewingdesign)\
**Post date:** [January 6, 2019, 11:09pm UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/4 "2019-01-06T23:09:06Z")

</div>

Hi Sapir,

Please feel free to ignore my previous post, as I figured out where I was going wrong. I solved my problem and now have the dataset filtering correctly with the code below:

```javascript
import wixUsers from 'wix-users';
import wixData from 'wix-data';

$w.onReady(function () {

 //Get current user email address
    wixUsers.currentUser.getEmail()
        .then( (email) => {
 let userEmail = email; //"user@something.com"
 
 //Filter the dataset
            $w("#myVehiclesSet").setFilter(wixData.filter()
                .eq("vehicle_user", email))
        })

});

```

Again, thank you SO much for your assistance.

---

<div class="post-metadata">

**Author:** ![suriyast](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/suriyast/32/8504_2.png) [@suriyast](https://forum.wixstudio.com/u/suriyast)\
**Post date:** [January 23, 2019, 11:17pm UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/5 "2019-01-23T23:17:03Z")

</div>

Hi  
I tried this and it does not work for [https://suriyast.wixsite.com/grant-gem](https://suriyast.wixsite.com/grant-gem)  
on the free members page -  
Can you help?

---

<div class="post-metadata">

**Author:** ![sapirh](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/sapirh/32/6655_2.png) [@sapirh](https://forum.wixstudio.com/u/sapirh)\
**Post date:** [January 27, 2019, 1:17pm UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/6 "2019-01-27T13:17:41Z")

</div>

Hi Uriya,

In the dataset properties there is an option to set a filter according to one of the fields.  
[https://support.wix.com/en/article/filtering-database-content-displayed-on-your-page](https://support.wix.com/en/article/filtering-database-content-displayed-on-your-page)

Best ,  
Sapir

---

<div class="post-metadata">

**Author:** ![suriyast](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/suriyast/32/8504_2.png) [@suriyast](https://forum.wixstudio.com/u/suriyast)\
**Post date:** [January 28, 2019, 12:17am UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/7 "2019-01-28T00:17:22Z")

</div>

Hi  
Thanks  
This does not help  
Like Scoot I need Filtering a Dataset by User (NOT Owner or other ui accisable one)

Tried Scott’s code but it dòes not work …

---

<div class="post-metadata">

**Author:** ![sapirh](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/sapirh/32/6655_2.png) [@sapirh](https://forum.wixstudio.com/u/sapirh)\
**Post date:** [January 28, 2019, 7:13am UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/8 "2019-01-28T07:13:31Z")

</div>

Hi Uriya

Add an onReady() function to your dataset and inside the handler add the setFilter() function:

```javascript
import wixUsers from 'wix-users';
import wixData from 'wix-data';

$w.onReady(async function () {
 let userEmail = await wixUsers.currentUser.getEmail()
    $w("#dataset1").onReady(() => {
        $w("#dataset1").setFilter(wixData.filter()
            .eq("User email", userEmail)
        )
    });

});

```

Best,  
Sapir

---

<div class="post-metadata">

**Author:** ![suriyast](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/suriyast/32/8504_2.png) [@suriyast](https://forum.wixstudio.com/u/suriyast)\
**Post date:** [January 30, 2019, 1:32am UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/9 "2019-01-30T01:32:12Z")

</div>

Hi Sapir,  
Tried to copy your code,  
Did not work, getting no results  
see screen shots

 ![](https://us1.discourse-cdn.com/wix/original/3X/8/5/85ed54e4ec387b084b3914abffdfe7de60a4a190.png)

 ![](https://us1.discourse-cdn.com/wix/original/3X/3/4/34f979734719e2a84d0ed8d1053eb71567de7258.png)

---

<div class="post-metadata">

**Author:** ![sapirh](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/sapirh/32/6655_2.png) [@sapirh](https://forum.wixstudio.com/u/sapirh)\
**Post date:** [January 31, 2019, 8:19am UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/10 "2019-01-31T08:19:36Z")

</div>

Hi,

You need to change the parameters according to your database:  
In the line below the “User email” parameter need to be the field key in your database.

```javascript
 .eq("User email", userEmail)

```

Best,  
Sapir

---

<div class="post-metadata">

**Author:** ![sapirh](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/sapirh/32/6655_2.png) [@sapirh](https://forum.wixstudio.com/u/sapirh)\
**Post date:** [February 7, 2019, 7:59am UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/11 "2019-02-07T07:59:03Z")

</div>

@jeff-haskins

Just input the email result into the input element.  
\*In the code below the id of the input element is “input1”

```javascript
wixUsers.currentUser.getEmail()
        .then( (email) => {
           $('#input1').value= email;
  });

```

Because this function is inside the onReady() function after the page is loaded the input element in the form will be filled in the current user’s email , so now he will only have to fill the rest of the inputs.

Best,  
Sapir

---

<div class="post-metadata">

**Author:** ![mh91](https://avatars.discourse-cdn.com/v4/letter/m/7993a0/32.png) [@mh91](https://forum.wixstudio.com/u/mh91)\
**Post date:** [February 13, 2019, 7:17am UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/12 "2019-02-13T07:17:55Z")

</div>

_BUMP_ Any update with this i have a similar issue and currently have the following code but does not return the right values from the database just the first row of values…

## (email addresses in my database are under the column ‘Client’)

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

$w.onReady( function () {

//Get current user email address  
wixUsers.currentUser.getEmail()  
.then( (email) =\> {  
let userEmail = email; //"user@something.com"

//Filter the dataset  
$w(“#dataset1”).setFilter(wixData.filter()  
.eq(“Client”, email))  
})

});

---

<div class="post-metadata">

**Author:** ![patrickwesterkamp](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/patrickwesterkamp/32/8122_2.png) [@patrickwesterkamp](https://forum.wixstudio.com/u/patrickwesterkamp)\
**Post date:** [June 6, 2019, 1:50pm UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/13 "2019-06-06T13:50:03Z")

</div>

@sapirh could i use this code for multiple values from the current user based on ID? For example:

```javascript
wixUsers.currentUser.id()
        .then( (email) => {
           $('#input1').value= email;
           
            .then( (list2) => {
              $('#input2').value= list2; 
              
               .then( (list3) => {
                 $('#input3').value= list3; 
  });

```

In this code the dataset would have email, list2, and list3.

---

<div class="post-metadata">

**Author:** ![garymstark](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/garymstark/32/10208_2.png) [@garymstark](https://forum.wixstudio.com/u/garymstark)\
**Post date:** [September 19, 2019, 9:00pm UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/14 "2019-09-19T21:00:01Z")

</div>

Sapir, this worked great for me to filter by email…THANK YOU! However, I now want to filter data to the Company associated with the currently logged in user. I do ask for Company on my custom member sign up form. However, I don’t see the Company field from the custom form in my Private Members Data collection, so I can’t figure out how to filter on that field. Can you help?

---

<div class="post-metadata">

**Author:** ![garymstark](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/garymstark/32/10208_2.png) [@garymstark](https://forum.wixstudio.com/u/garymstark)\
**Post date:** [September 19, 2019, 9:19pm UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/15 "2019-09-19T21:19:00Z")

</div>

Sapir…can you filter by domain address, i.e. anything @companyname.com?

---

<div class="post-metadata">

**Author:** ![garymstark](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/garymstark/32/10208_2.png) [@garymstark](https://forum.wixstudio.com/u/garymstark)\
**Post date:** [September 20, 2019, 4:34pm UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/16 "2019-09-20T16:34:43Z")

</div>

Hi! I have code that is doing a good job of matching the email address of the currently logged in user to the “submittedByEmail” in my collection. However, I would prefer to filter by the Domain of the currently logged in user, which I have as a column in my dataset as “submittedByDomain”. Do you how I would alter the code so that it shows the data for the currently logged in user that matches the “submittedByDomain” of that user in my dataset?

**import** wixUsers **from** ‘wix-users’;  
**import** wixData **from** ‘wix-data’;

$w.onReady( **async function** () {  
**let** userEmail = **await** wixUsers.currentUser.getEmail()  
$w(“#dataset1”).onReady(() =\> {  
$w(“#dataset1”).setFilter(wixData.filter()  
.eq(“submittedByEMail”, userEmail)  
)  
});

});

---

<div class="post-metadata">

**Author:** ![benkelvinharries](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/benkelvinharries/32/16184_2.png) [@benkelvinharries](https://forum.wixstudio.com/u/benkelvinharries)\
**Post date:** [November 30, 2019, 10:32pm UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/17 "2019-11-30T22:32:21Z")

</div>

Most likely the “Client” does not refer to the id of the column in data go to data column and click on setting

---

<div class="post-metadata">

**Author:** ![evanluck](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/evanluck/32/12592_2.png) [@evanluck](https://forum.wixstudio.com/u/evanluck)\
**Post date:** [December 22, 2019, 2:13am UTC](https://forum.wixstudio.com/t/filtering-a-dataset-by-user-not-owner/14772/18 "2019-12-22T02:13:13Z")

</div>

I’m essentially doing a similar thing here but running into issues.

I need to create some sort of query based on the currentUser and run it against a second dataset on the page.

I need to write the email (currentUser) and the first name and last name from the first data set (members) to the second dataset if they don’t already exist there and in page’s form allow the user to edit their other details in the second data set. Sapir or others is there a way you could assist me?

 ![](https://us1.discourse-cdn.com/wix/original/3X/d/a/da41040547c1672d5812304f23471bdb0ef079e3.png)
