Reputation: 1
I'm trying to get second latest item from Mongodb Collection, to make sure the latest alerts are displayed "alert time" is set to desc. i got the first item using firstordefault() method, i've tried different methods to get the 2nd item, but wasn't able to
Upvotes: 0
Views: 95
Reputation: 71
You can get only 2 items from your query and then pick the last one
collection.AsQueryable().Where(i => i.TestCaseID == CaseID).OrderByDescending(i => i.AlertTime).Take(2).ToList().LastOrDefault();
Upvotes: 1