Schemas: MinLength

Setting the minimum number of characters for a field.

🪶 This property defines the 'minimum number' of characters that a field of type String must have.

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