Schemas: MinList
Defining a minimum value of indices in an array.
🪶 The minList option in MerlinDB is used to define the minimum value of indexes allowed for an array 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( ) ;5 merlin.connect( "MY-STORE-DATABASE") ; 6 7 const ClientSchema = Schema( { 8 hobbies: { type: Array , minList: 3 } , 9 //Or defining a message 10 name: { 11 type: Array , 12 minList: [ 3 , "Minimum 3 hobbies allowed!" ] 13 } 14 } ) ; 15 16 var clientModel = merlin.model( "Users", ClientSchema) ;17 18 clientModel.insert( { 19 hobbies: ["Basketball"] 20 } ) .then( e => { 21 /* OK... */ 22 } ) .catch( e => { 23 console.log( e) ; 24 //returns Minimum 3 hobbies allowed! 25 } ) ;