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
  • Creating indexes
  • Index Types
  • Single field index
  • Compound index
  • External references

Was this helpful?

Edit on GitHub
  1. dashboard
  2. Database
  3. Collections

Indexes

Overview of collection indexes

PreviousTriggersNextShared Forms

Last updated 4 years ago

Was this helpful?

To optimize your find queries you can add indexes for your collection. Because we are using MongoDB internally as a provider, indexes should be set according to MongoDB standards.

Creating indexes

Indexes can be added inside a collection page, Indexes tab. Here you need to provide fields with an index value. Optionally you can provide options for an index.

To create an index, modify provided <field> and <type> fields. The <field> is your field name (unique name) and <type> is an index value for that field. You can also specify some options. Though options currently are not fully supported so you can leave the options field as it is.

Indexes take up some available storage in your database. So don't overuse indexes if you are nearing your storage limit.

Also, indexes decrease performance when inserting, updating, deleting your records as the keys in the index needs to be adjusted.

Index Types

The following provides some available examples displaying various available options for your indexes.

Single field index

Consists of one field. Here <field> is first_name and <type> is 1.

{ "first_name": 1 }

Compound index

Consists of multiple fields. Here we create an index on two fields. In this case <field> representations are first_name and age, and <type> representations are 1 and -1.

{ "first_name": 1, "age": -1 }

Here values 1 and -1 tells how to sort index keys. For a single field the order does not matter. For compound, it matters when using sorting. It matters in two ways:

  1. In a sort query, your fields must be listed in the same order as in index (although you are not required to use all fields that are in the index, you can use a subset). For example, if you call a find method and provide a sort query{ first_name: 1, age: -1 }then index will be used. But if you change positions like this{ age: -1, first_name: 1 }then your index will not be used.

  2. In sort query your fields must match the sort direction as in index or must match the inverse sort direction . for example, if you call a find method and provide a sort query { first_name: 1, age: -1 } or { first_name: -1, age: 1 } then the index will be used. But if you only inverse one of the fields like{ first_name: -1, age: -1 }then the index will not be used.

If you want to put indexes on nested forms, then you can do that separating nested field name and a field inside the nested field by a dot.

{ "address.zip": 1 }

External references

As CodeMash is heavily using MongoDB database internally, the following resources explain more on how to form indexes.

Full indexes manual
Index add view