Cursor Methods: Pretty

Returning readable documents from a collection.

🪶 The pretty method formats the output of documents returned by a query to make them more readable.

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(
  • )
  • ;
    5merlin
  • .connect(
  • "USER-DATABASE"
  • )
  • ;  
    6
  • var
  • userModel = merlin
  • .model(
  • "User", <userSchema>
  • )
  • ;
    7
    8
  • //cursor.pretty();
  • 9userModel
  • .find(
  • {
  • age:
  • 33
  • }
  • )
  • 10
  • .pretty(
  • )
  • .then(
  • e =>
  • {
  • 11   console
  • .log(
  • e
  • )
  • ;
    12  
  • //Transform this:
  • 13   [...]
    14  
  • //to:
  • 15   [
    16      
  • {
  • 17        
  • name:
  • {
  • 18            
  • first:
  • "Chris",
    19            
  • last:
  • "Axxwell"
    20        
  • }
  • ,
    21        
  • age:
  • 13
  • 22      
  • }
  • ,
    23      
  • {
  • 24        
  • name:
  • {
  • 25            
  • first:
  • "Maya",
    26            
  • last:
  • "Axxwell"
    27        
  • }
  • ,
    28        
  • age:
  • -
  • 9
  • 29      
  • }
  • ,
    30      
  • //...
  • 31   ]
    32
  • }
  • )
  • ;