Cursor Methods: Limit
Limiting the number of documents returned in a collection in the database in MerlinDB.
🪶 The
Setting cursor.limit( { name: 1 } ) causes the fields to be sorted in ascending order by name, if using -1 sorts in descending order.
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 var userModel = merlin.model( "User", <userSchema>) ;7 8 //cursor.limit(<number>); 9 userModel.find( { name: "Sam"} ) 10 .limit( 3 ) 11 .then( e => { 12 //Returns all '3' first documents whose name is 'Sam' 13 } )