CodeMash
  • 🚀Backend as a service
  • 🦄Roadmap
  • 🍕Release Notes
  • Installation
    • Managed Service
    • 🏗️AWS-CDK
    • 🏗️Azure
    • 🏗️Docker
    • 🏗️GC
    • 🏗️Terraform
  • dashboard
    • CodeMash Cloud
    • Project
    • Membership
      • Users
      • Roles
      • Policies
      • Triggers
      • Integrations
        • Apple
        • Azure
        • Facebook
        • Google
        • Twitter
      • Settings
    • Database
      • Collections
        • Schema
          • From Template
          • Structure
        • Tabs
        • Triggers
        • Indexes
        • Shared Forms
      • Taxonomies
        • Terms
        • Schema
        • Settings
      • Aggregation
      • Imports
      • Exports
      • Backups
    • Files
      • Integrations
        • CodeMash
        • S3 Bucket
    • Notifications
      • Push
        • Push Templates
        • Push Templates API
        • Push Notifications
        • Push Notifications API
        • Devices
        • Devices API
        • Integrations
          • Firebase
          • One Signal
          • Expo
      • Email
        • Email Templates
        • Emails
        • Integrations
          • AWS SES
          • Twilio Sendgrid
          • Mailgun
      • 🏗️Server events
      • 🏗️Sms
    • Payments
      • Integrations
        • Apple Pay
        • Google Pay
        • Stripe
        • Kevin.
        • Paysera
        • Decta
    • Scheduler
    • Logs & Monitoring
    • Code
      • Functions
        • Function Inputs
        • Function Templates
          • Node.js
          • Python
          • Ruby
          • Java
          • Go
          • .NET Core
      • CodeMash Functions
        • Google Functions
          • Google Calendar
          • Google Gmail
        • Microsoft Functions
          • Microsoft 365 Users
          • Microsoft 365 Calendar
        • Collection Find
        • Collection Update
        • Users Find
        • Image Resize
        • Html To Pdf
        • Word Document
        • Barcode
        • QR Code
        • Send Email
        • Send Notification
        • Email Reminder
        • Notification Reminder
      • Integrations
        • AWS Lambda
        • Google Cloud Functions
        • Azure Functions
  • Other Topics
    • Apple
      • Developer Portal
      • Bundle Identifier
      • Team ID
      • Service ID
      • Key ID
    • Triggers
    • Tokens Binding
      • Project Tokens
      • Initiator Tokens
      • Receiver Tokens
      • Request Tokens
      • Operation based tokens
      • Template Functions
    • Search parameters
      • Paging
      • Filter
      • Sort
      • Projection
    • data-models
    • Errors
  • SDK
    • Node.js
    • TypeScript
    • .NET
    • 🏗️Go Lang
    • 🏗️Flutter
    • 🏗️Swift
    • 🏗️Kotlin
  • CLI
    • 🏗️CodeMash CLI
  • API
    • Get Started
    • Prerequisites
    • How to test?
    • Cors
    • Project
    • Membership
      • Authentication
      • Users
    • Database
      • Collections
        • Aggregate
        • Change Responsibility
        • Count
        • Delete
        • Delete Many
        • Distinct
        • Find
        • Find One
        • Insert
        • Insert Many
        • References
        • Replace
        • Update
        • Update Many
      • Taxonomies
        • Find
    • Files
    • Code
    • Notifications
      • Push
      • Emails
      • Server Events
      • 🏗️Sms
    • Payments
    • Scheduler
    • Logs & Monitoring
Powered by GitBook
On this page
  • How to use
  • External references

Was this helpful?

Edit on GitHub
  1. Other Topics
  2. Search parameters

Projection

Overview of projection document

PreviousSortNextdata-models

Last updated 5 years ago

Was this helpful?

Projection document allows you to specify what fields should be returned from a find request. This can significantly reduce the amount of data being transferred as it will only return the fields that you ask for. Currently projections are only supported on your collections. Other resources are returned as full objects.

How to use

A format of a projection document is shown below. You provide a field, which is a field saved inside a database, and a value which can be either 1 or 0 (include or exclude).

{ <field>: <value>, <field2>: <value2>, ... }

Projection document can be of type inclusive or exclusive. That means that projection can only have one of the values in a document (1 or 0). It cannot have mixed values. This does not imply for _id field which can be set to 0 even if other fields are set to 1.

A projection { "name": 1, "age": 0 } is not valid as it mixes 1 and 0 inside a document.

An inclusive projection is shown below. Here we have two fields which we know exists in a database. This will return name, age and _id fields. Any other fields that would exist in a record (for example, phone, address) will be excluded, because we specifically told to only include these fields. This is a valid document because only one type of value is set which is 1.

{ "name": 1, "age": 1 }

Field _id will always be returned if not set to 0 even if it's not included inside a projection document. This field can be set to 0 even in inclusive projections.

An exclusive projection is shown below. This will return all fields except for a name and age. You can use this type of projection when you want to exclude lesser amount of fields than to include.

{ "name": 0, "age": 0 }

To project items inside an object or array, separate fields by a dot.

{ "address.street": 1, "name": 1, "_id": 0 }

External references

As CodeMash is using MongoDB database internally, the following resources explain more on how to use projection.

Projection examples