# Population Constrains

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

```javascript
{
    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,
          }
        }
      }
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://nomadas.gitbook.io/mongo-server/miscellaneous/population-constrains.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
