0

I have a query something like this in mongoose.

var query=Videopost.findOne({}, {}, { sort: { '_id' : -1 } });

I want to exclude last record inserted in database from result.

Any help will be appreciated!!!

styvane
  • 59,869
  • 19
  • 150
  • 156
Kishor Mishra
  • 75
  • 3
  • 11
  • Possible duplicate of [How to paginate with Mongoose in Node.js?](http://stackoverflow.com/questions/5539955/how-to-paginate-with-mongoose-in-node-js) – styvane Dec 19 '15 at 06:40
  • `findOne` is always going to return only one document. Did you mean `find()`? – BatScream Dec 19 '15 at 07:17
  • chain `skip(1)` to the query. It would skip the most recently added record. – BatScream Dec 19 '15 at 07:30
  • @BatScream : i have tried that Videopost.find({}).skip(1).. but it is skipping first record what i have inserted not the last one. – Kishor Mishra Dec 19 '15 at 07:37
  • you need to keep the sort and skip operations chained together- `find({}).sort({"_id":-1}).skip(1)` – BatScream Dec 19 '15 at 07:39
  • Thanks for your support!! Can you post in the answer @BatScream – Kishor Mishra Dec 19 '15 at 07:42
  • you are most welcome @KishorMishra. I think the question has an answer on the link posted as part of the first comment.so If i post an answer here, it would be repetitive. Will be glad to post next time around. Happy coding. – BatScream Dec 19 '15 at 07:47

0 Answers0