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. Basics

Default values

With Defaults, you can assign default properties on resource creation / update, if the function result includes the keys $owner, $timestamps or $changelog $version, it will trigger special behaviors

module.exports= {
  resources: {
    dogs: {
      post:{
        permissions:["user:permission"],
        default:(resource,user)=>({
          ...resource,
          $owner:true, // this will be saved as resourceName_id: id, so you can use it with the populate feature defined in the Relationships section
          $timestamps:true, // createdAt, updatedAt
          $version: true,
        })
      }
    },
  }
}
PreviousRoute logicNextInput validation and Output Formatting

Last updated 6 years ago

Was this helpful?