Schemas: MaxList
Defining a maximum value of indices in an array.
🪶 The maxList option in MerlinDB is used to define the maximum allowed index value 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 , maxList: 2 } , 9 //Or defining a message 10 name: { 11 type: Array , 12 maxList: [ 2 , "Maximum 2 hobbies allowed!" ] 13 } 14 } ) ; 15 16 var clientModel = merlin.model( "Users", ClientSchema) ;17 18 clientModel.insert( { 19 hobbies: ["Basketball", "Games", "Movies" ] 20 } ) .then( e => { 21 /* OK... */ 22 } ) .catch( e => { 23 console.log( e) ; 24 //returns Maximum 2 hobbies allowed! 25 } ) ;