Schemas: Min

Setting a minimum allowable value for a numeric field.

🪶 The min option in MerlinDB is used to set the minimum value allowed for a numeric field.

1
  • import
  • MerlinDB,
  • {
  • Schema
  • }
  • from
  • "@chrisaxxwell/merlin-db";
    2
  • //Or if you are using 'merlindb.max.js' just call 'new MerlinDB()';
  • 3
    4
  • const
  • merlin =
  • new
  • MerlinDB(
  • )
  • ;
    5merlin
  • .connect(
  • "MY-STORE-DATABASE"
  • )
  • ;
    6
    7
  • const
  • ClientSchema =
  • Schema(
  • {
  • 8  
  • age:
  • {
  • type:
  • Number
  • ,
  • min:
  • 17
  • }
  • ,
    9  
  • //Or defining a message
  • 10  
  • name:
  • {
  • 11      
  • type:
  • Number
  • ,
    12      
  • min:
  • [
  • 17
  • , "You are very young, you need to be at least
  • 17
  • years old!" ]
    13  
  • }
  • 14
  • }
  • )
  • ;
    15
    16
  • var
  • clientModel = merlin
  • .model(
  • "Users", ClientSchema
  • )
  • ;
    17
    18clientModel
  • .insert(
  • {
  • 19    
  • age:
  • 12
  • 20
  • }
  • )
  • .then(
  • e =>
  • {
  • 21  
  • /*  OK...  */
  • 22
  • }
  • )
  • .catch(
  • e =>
  • {
  • 23   console
  • .log(
  • e
  • )
  • ;
    24  
  • //returns You are very young, you need to be at least 17 years old!!
  • 25
  • }
  • )
  • ;