Schemas: Types
Defining the characteristics of a field in a document.
đĒļ A SchemaType defines the characteristics of a field in a MerlinDB document.
In shorter words, you define the allowed data type of the field.
String: To store text values;
Number: To store number values, whether integer or decimal;
Date: To store dates.
Array: To store arrays of values;
Function: To store functions;
Object: To store nested objects;
Boolean: To store boolean values ââ(true/false);
1 import MerlinDB, { Schema} from "@chrisaxxwell/merlin-db";2 //Or if you are using 'merlindb.min.js' just call 'new MerlinDB()'; 3 4 const ClientSchema = Schema({ //Or merlin.Schema(<your-Schema>) 5 //The data type accepted in 'phone' is number type 6 phone: Number , 7 //Or to allow multiple types 8 phone: [String , Number ], 9 //Or 10 phone: { type: Number } , 11 //Or 12 phone: { type: [String , Number ]} , 13 } )
You can pass an error message like this:
1 import MerlinDB, { Schema} from "@chrisaxxwell/merlin-db";2 //Or if you are using 'merlindb.min.js' just call 'new MerlinDB()'; 3 4 5 const ClientSchema = merlin.Schema({ //Or Schema(<your-Schema>) 6 phone: [ [String , Number ], "Invalid phone number"], 7 //Or 8 phone: { type: [ [String , Number ], "Invalid phone number"]} , 9 } )