Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • MongoDB : Sorting

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 731
    Comment on it

    MongoDB - Sorting

    In any application we need to show list in certain order. Generally we show's user feeds in descending order. This can be achieve in MongoDB through "sort" properties.

    e.g. We need to sort student name in ascending order.

    db.collection.find().sort({ columnname : 1})
    

    1 belongs to ascending order. -1 belongs to descending order.

    In above query if we want to show student name in desecending order then query should be:

    db.collection.find().sort({columnname: -1 })
    

    We can sort multiple column with the following query.

    db.collection.find().sort({columnname1: -1 , columnname2: 1 })
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: