Mongo Server
  • Introduction
  • Getting started
  • Basics
    • Routing and Queries
    • Restrict endpoints
    • Route logic
    • Default values
    • Input validation and Output Formatting
  • Auth and permissions
    • Login and authentication
    • Permission handling
    • Local authentication
    • Magic Links and codes
  • Automatic Documentation
    • Server description
    • Swagger Docs
  • Miscellaneous
    • Db Seeding
    • Mailing settings
    • Roadmap
    • Population Constrains
Powered by GitBook
On this page

Was this helpful?

  1. Miscellaneous

Population Constrains

You can add constrains in the $populate field in server side:

{
    resources:{
      companies:{
        // use population object to stablish population constrains
        population:{
          
          // the populate resource that will be constrained when populated
          employees:{
            // this parameter allows you to add an extra query
            $match: {/* query */}
            
            // alternatively you can use an function with express request as a parameter
            $match(req){return {/* mongodb query */}}
            
            // this will sort by createdAt field in employeed document
            $sort: 'createdAt',
            
            // this will sort by desc "createdAt" order 
            $order: 'desc',
            
           // this will limit to a max of two items
            $limit: 2,
          }
        }
      }
    }
}

PreviousRoadmap

Last updated 5 years ago

Was this helpful?