Mongodb Classroom image

Anil  Bist / Professional / DataBase

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2|
Lessons:-limit, skip, sort and count the results of the find() method

To sort descending by the field name:

db. test . find ( { } ) .sort ({ "name" : - 1 } )

 

Will return:

 

If you want to sort ascending just replace -1 with 1

To count the results:

db. test . find ( { } ) .count ( )

 

Will return:

      5                  

 

Also combinations of this methods are allowed. For example get 2 documents from descending sorted collection skipping the first 1:

db. test . find ( { } ) .sort ({ "name" : - 1 }).skip ( 1 ). limit ( 2 )

 

Will return:

 

 
 
 
image
Anil  Bist

Skills    Mongodb

Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,
Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-

I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore

 

  Students (0)