How to filter graph chart from DB?

I have managed to connect the graph to DB following the article here: https://www.vorbly.com/Vorbly-Code/WIX-IFRAME-GRAPHS-%26-CHARTS-WITH-FILTERS

I need it to display info only related to the member currently logged in. So in the DB collection I have assigned to each member a unique account number.

The issue is that the chart displays all the information in the database for all users.

Any ideas on how to filter the chart to show only lets say “owner” information?
For any adjustment that can be made via code please see code below:
Thanks

import wixData from 'wix-data';
import {monthSort} from 'public/months';

$w.onReady(function () {
$w("#table1").columns = [
{
"id": "col1",
"dataPath": "month",
"label": "Month",
"type": "string"
},
{
"id": "col2",
"dataPath": "amount",
"label": "Number of Trades",
"type": "number"
},
{
"id": "col3",
"dataPath": "total",
"label": "Total Repay",
"visible": true,
"type": "string"
}
];
wixData.query("Expenses")
.ascending("month")
.limit(1000)  // Max limit of 1,000 //

.contains("fxrAccount", $w("#dropdown1").value)
.find()
.then( (result) => {
const months = result.items.map(x => x.month)
.filter((obj, index, self) => index === self.indexOf(obj))
.sort(monthSort);
const aggregated = months.map(x => {
return {
month: x,
total: result.items.filter(obj => obj.month === x)
.map(z => z.amount)
.reduce((sum, current) => sum + current)
};
});
$w("#table1").rows = aggregated;
let tableArr = [];
for ( var i = 0; i < $w("#table1").rows.length; i++ ) {
tableArr.push (
$w("#table1").rows[i]["total"]
)
}
$w("#html1").postMessage(tableArr);
});
});

export function dropdown1_change(event, $w) {
$w("#html1").show();
let product = $w("#dropdown1").value;

$w("#table1").columns = [
{
"id": "col1",
"dataPath": "month",
"label": "Month",
"type": "string"
},
{
"id": "col2",
"dataPath": "amount",
"label": "Number of Trades",
"type": "number"
},
{
"id": "col3",
"dataPath": "total",
"label": "Total Repay",
"visible": true,
"type": "string"
}
];

wixData.query("Expenses")
.ascending("month")
.eq("type", product)
.limit(1000)
.contains("fxrAccount", $w("#dropdown1").value)
.find()

.then( (result) => {
const months = result.items.map(x => x.month)
.filter((obj, index, self) => index === self.indexOf(obj))
.sort(monthSort);
const aggregated = months.map(x => {
return {
month: x,
total: result.items.filter(obj => obj.month === x)
.map(z => z.amount)
.reduce((sum, current) => sum + current)
};
});

$w("#table1").rows = aggregated;
let tableArr = [];
for ( var i = 0; i < $w("#table1").rows.length; i++ ) {
tableArr.push (
$w("#table1").rows[i]["total"]
)
}

console.log(tableArr);
$w("#html1").postMessage(tableArr);
});

}

Hi.

You need to use .eq(‘accountNumberFieldKey’, loggedInMemberAccountNumber). You may need to use _id field to identify the logged in member. Checkout our API here .

Good luck!

Awesome - Thanks Sam!

Thank you Sam for your response.

Unfortunately that does not seem to do the trick so I have used .contains instead.

The issue is I think in the graph chart code. As it “reads” the months field key rather than the account number. I think that is the case because I have used 2 same months in the DB belonging to different “members” but yet the table combines the two numbers in to one.

Very messy and difficult problem to solve.

Thank you for taking the time to respond!