Choose which fields wixData.query will return from queries

Hey there!I have a Data Collection with more than 75 fields in it. A lot of times for repeaters and such I only need like four of them returned. I suspect that the pages will be slower if I return 100 records with 75 large fields instead of 4 of them?

I would like to do this:

import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .fields("_id","title","description","url","image")
  .find()
  .then( (results) => {
    let firstItem = results.items[0]; //see item below
  } )
  .catch( (err) => {
    let errorMsg = err;
  } );

/*  firstItem is:
 *
 *  {
 *    "_id":          "00001",
 *    "title":       "Some title",
 *    "description": "Some description",
 *    "url": "https://www.domain.com",
 *    "image":        "wix:image//something",
 *  }
 */

You can code an afterGet or afterQuery hook and get only those four fields. Let us know if it performs better.

Bummer! Why didn’t I think of that on my own… I will test, but I stil think it would be nice for making coding a bit easier and arrays a bit smaller. A lot of people is looping through results.items.forEach to make their own array after results get back.

Hi, I have the exact same issue. I have a collection with 3 fields: camera maker, model and a value for each, I would like the user to select a camera maker from a dropdown list (already populated with values and then run a query that will poplulate only the models of the selected camera maker to a second dropdown called model.
Can you give an example with the exact syntax in the after query function in the data.js? I’ve tried a few variations and nothing works

let title=firstItem["title"]