0

I can't find the answer. I have a query that can return many answer and I want to get the last one. How to do it?

db.users.find({username: "bob", sort: {createdAt: -1}}).first()

I would like something like this.

BoumTAC
  • 3,531
  • 6
  • 32
  • 44

1 Answers1

0

do this to get last N records :

function last(N) {
    return db.collection.find().skip(db.collection.count() - N);
}
Pratik Gujarathi
  • 929
  • 1
  • 11
  • 20