I have a collection with 1000 items. I want to sort them per date (SaveDateUtc field) and remove the top 10 of them, so I’m left with the 990 newest items in my collection.
I could do a Find and then a Remove, no problem, but it’d be much better if I could do this with just a Remove call. But I can’t find a way to sort and set top 10 through the query.
So my question is, can I do this in just one call?
(I’m using the C# driver)
Actually there was similar question: MongoDB find and remove – the fastest way
But unfortunately
findAndUpdatecannot be restricted by records number. So my propositions to you: