Help with Data set returned data

I’m running a dataset query to return data where email address = input text value. The query works and records are returned successfully, however When I look in Chrome developer tools, I can see all fields are being returned from the collection. Most of these fields are not required and some contain sensitive information, but I can see the actual values under the network tab.
Is there a way to specify the fields to be returned when the query is executed? I only need status, applicationamount, applicantname

Nope, that is one of the drawbacks with datasets: you cannot do projections (select fields to be returned). There is only one solution: switch from datasets to wix-data, run a query on the backend and filter the returned result (in the backend), then return the subset to the frontend. There is an article about this in the documentation, written by Sam, from memory.

How do I do that, this is the query I’m running which is using wix data:

import wixData from “wix-data” ;

function query_Data(){
wixData.query( “Applications” )
.eq( “applicantEmail” , $w( “#input1” ).value)
.find()
.then(res => {
console.log(res)
$w( “#table1” ).rows = res.items;
if (res.totalCount === 0 ){
$w( ‘#text26’ ).show();
}
else {
$w( “#table1” ).expand();
}
});
}

Yes, you are using wix-data, but on the frontend. There’s no point in defining a projection there, a savvy user could guess the name of other fields(columns) and add them to the query. How I do it is like this:

  1. write a backend function, lets say getData(strEmail, someOtherValue). I do not know what $w( " #input1 " ).value) holds.
  2. you cannot call backend function directly from frontend. You need to go thru a .jsw file. So create a .jsw file and create a shadow function there called getDataJSW(strEmail, someOtherValue), which simply calls the first backend function.
  3. in the backend function, you do the query, filter the result (look at Sam’s article), return it so the .JSW file
  4. .JSW-file returns it to frontend
  5. Bob’s your uncle

EDIT: and on the frontend, you just call the getDataJSW(…), wait for the result and then display it.

do you have a link to the article you refer to? Apologies I’ not a developer so I need basic instructions.

I’ve got the jsw working and can call it from the front end, I still don’t know how to limit the fields returned and also how do I present the results to the front end so they can be presented in a table?

This is the backend code.

import wixData from ‘wix-data’ ;

export function queryApplications(Email) {
wixData.query( ‘Applications’ )
.eq( “applicantEmail” ,Email)
.find()
.then((results) => {
console.log(results.items);
})
. catch ((err) => {
console.log(err);
});
}

Previously when all i the front end, the results of the query could be put straight into my table

function query_Data(){
wixData.query( “Applications” )
.eq( “applicantEmail” , $w( “#input1” ).value)
.find()
.then(res => {
console.log(res)
$w( “#table1” ).rows = res.items;
});
}

How do i get results.items to the front end?

I found it for you: https://support.wix.com/en/article/velo-best-practices-for-improving-performance-in-wix-sites-with-data

At the bottom “Downloading only the fields you need”

And about how to call it from the frontend:

  1. in your page, import the function from .jsw file at the top, just like you imported wix-data before
  2. if you call it from the page onReady, make it async, like so:
$w.onReady(async function () {

If you call it from another function than the onReady function, just make that function async
3) do this inside the function:

let arrResult = await queryApplications(Email) ;
$w("#table1").rows = arrResult.items; 

So I’ve updated my code to:
async function query_Data(){
let arrResult = await queryApplications($w( ‘#input1’ ).value) ;
$w( “#table1” ).rows = arrResult.items;
if (arrResult.items.totalCount === 0 ){
$w( ‘#text26’ ).show();
}
else {
$w( “#table1” ).rows = arrResult.items;
$w( “#table1” ).expand();
}
}

However when I preview it I get

which relates to $w( “#table1” ).rows = arrResult.items; The query is no no longer returning results at the front end.

I’m calling this function from on ready:

export function searchbutton1_click(event) {
$w( ‘#text26’ ).hide();
$w( “#table1” ).collapse();
query_Data();

}

The jsw code is:

import wixData from ‘wix-data’ ;

export function queryApplications(Email) {
wixData.query( ‘Applications’ )
.eq( “applicantEmail” ,Email)
.find()
.then((results) => {
console.log(results.items);
})
. catch ((err) => {
console.log(err);
});
}

The jsw tests ok if I use a valid email address and returns 34 records. when I run it via the front end it also returns 34 records in the developer console, so the query is working front end to back, but it doesn’t like the results.