Page Contents

A fields filter specifies properties (fields) to include or exclude from the results.

Node.js API

{ fields: {propertyName: <true|false>, propertyName: <true|false>, ... } }

Where:

  • propertyName is the name of the property (field) to include or exclude.
  • <true|false> signifies either true or false Boolean literal. Use true to include the property or false to exclude it from results.

By default, queries return all model properties in results. However, if you specify at least one fields filter with a value of true, then by default the query will include only those you specifically include with filters.

REST API

filter[fields][propertyName]=true&filter[fields][propertyName]=true...

Note that to include more than one field in REST, use multiple filters.

Check out the usage of stringified JSON format in a REST query.

Examples

Return customer information only with name and address, and hide their id:

Node.js API

await customerRepository.find({fields: {id: false, name: true, address: true}});

REST

Include all required properties as a workaround: /customers?filter[fields][name]=true&filter[fields][address]=true

Or use stringified JSON format:

/orders?filter={"fields":{"name":true,"address":true,"id":false}}

Returns:

[
  {
    name: 'Mario',
    address: '8200 Warden Ave'
  },
  {
    name: 'Luigi',
    address: '999 Avenue Rd'
  },
  ...
]

Exclude the password property:

Node.js API

await userRepository.find({fields: {password: false}});

REST

Include all properties except password as a workaround:

/users?filter[fields][name]=true&filter[fields][email]=true&filter[fields][id]=true...

Or use stringified JSON format:

/users?filter={"fields":{"password":false}}

Notice that fields clause is to include/exclude the result from the database, e.g if you would like to check password for users, the above example would fail as password is undefined. If you need the property and also want to hide it from the response, set it as a hidden property in the model definition.