Model Methods: Data Size
Getting the total size of data in a collection in MerlinDB.
🪶 The dataSize method allows you to get the total size of a collection in the database.
It has a parameter with 2 options:
string (Boolean): Returns the value in a string;
format {("kB"|"MB"|"GB")}: Formats the values that are in bytes to kilobyte or megabyte or gigabyte.
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( "USER-DATABASE") ; 6 7 const UserSchema = Schema( { 8 name: String , 9 age: Number 10 } ) ; 11 12 var userModel = merlin.model( "User", UserSchema) ;13 14 //userModel.dataSize(<options>); 15 userModel.dataSize( { 16 17 string: true , 18 format: "MB" 19 20 } ) .then( e => { 21 console.log( e) ; 22 //returns '4.32 MB'; 23 } ) ;