1 belowu
1 belowu

Reputation: 1

Mongodb - Get 2nd item from collection

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

Prev Result

Collection screen

Upvotes: 0

Views: 95

Answers (2)

1 belowu
1 belowu

Reputation: 1

Sorry for the late response

Skip(1).FirstorDefault() did the trick

Upvotes: 0

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

Related Questions