MongoDB find get position of document after sort

Viewed 1994

Is it possible to get the position of a document for a query? Example:

db.users.find().sort({created:-1})

returns:

0: {name:"user1",created:5}
1: {name:"user1",created:4}
2: {name:"user1",created:3}
3: {name:"user1",created:2}

How to get these indexes (0,1,2,3)?

0 Answers
Related