fields( )


Lists the fields to return in a query's results.

The fields() function returns only the specified fields in the query's results.

You can use include() in conjunction with fields() to get referenced items.

When fields() receives an empty or invalid property, the query behaves as follows:

  • When no fields are specified, the query returns all fields.
  • When multiple fields are specified but some are invalid, invalid fields are ignored and valid fields are returned.
  • When only invalid fields are specified, only the default _id field is returned.
Method Declaration
Copy
Method Parameters
propertyNameArray<string>Required

Properties to return. To return multiple properties, pass properties as additional arguments.

Was this helpful?
Yes
No