Should you query mongodb database or get all and sort after code example Example: mongodb sort query db.Employee.find().sort({Employeeid:-1}).forEach(printjson)