MongoDB: How to find nth highest salary from collection -


i need find nth highest salary in mongodb employees collection. helpful if gimme idea of applying joins in mongodb.

this should work

db.employees.find({}).sort({"emp salary":-1}).limit(1) //for first highest salary  db.employees.find({}).sort({"emp salary":-1}).skip(1).limit(1) // second highest salary 

similarly can db.employees.find({}).sort({"emp salary":-1}).skip(nthvarible - 1).limit(1).


Comments