Projection

Projection

You can use a Projection to return only specified collection columns. You can do this by adding a proj parameter to your request.

Examples

Here is how to retrieve only the studentName column:

curl -X POST \
  -H "X-Appery-Database-Id: 544a5cdfe4b03d005b6233b9" \
  -H "Content-Type: application/json" \
  -d '{"proj":{"studentName":1}}' \
  https://api.appery.io/rest/1/db/collections/students/query
When the certain column is marked with number 1 – MongoDB assumes that all other columns shouldn’t be retrieved. To retrieve several columns, specify them, separated by commas:
curl -X POST \
  -H "X-Appery-Database-Id: 544a5cdfe4b03d005b6233b9" \
  -H "Content-Type: application/json" \
  -d '{"proj":{"studentName":1,"studentId":1}}' \
  https://api.appery.io/rest/1/db/collections/students/query
You can also specify which column should be excluded from the result. In this case, all columns will be retrieved except the excluded ones. To do this, mark column name with zero:
curl -X POST \
  -H "X-Appery-Database-Id: 544a5cdfe4b03d005b6233b9" \
  -H "Content-Type: application/json" \
  -d '{"proj":{"studentName":0}}' \
  https://api.appery.io/rest/1/db/collections/students/query
You cannot mix including and excluding fields due to MongoDB limitation.

You can mix the include parameter with proj to specify what columns should be retrieved from related object.

The following example retrieves only studentName and studentId fields from the collection in which the request was made, and only email from the related object:

curl -X POST \
  -H "X-Appery-Database-Id: 544a5cdfe4b03d005b6233b9" \
  -H "Content-Type: application/json" \
  -d '{"include":"owner", "proj":{"studentName": 1, "studentId":1, "owner": {"email": 1}}}' \
  https://api.appery.io/rest/1/db/collections/students/query

📘

Note

Read more about MongoDB projection.