I have an aggregate pipeline which is pretty much:
[
{ "$match" : <filter out some basic stuff>},
{"$redact" : <more complicated filter>},
{"$limit":x}
]
Assume that I have 10 documents, and I expect the 2nd, 5th, and 8th to be returned
If I set x to 10 then I will get all 3
if I set x to 8 then I will still get 3
if I set x to 7 then I only get the 2nd and 5th
if I set x to 4 then I only get the 2nd
If I set x to 1 then I don't get any results
So based on my experiments it looks like the limit is applied to the input, not the output. The same aggregate run against mongoDb behaves as I would expect (x == 3 returns 2nd,5th,8th x == 2 return 2nd,5th x==1 returns 2nd)
How do I get it to behave the same as mongoDb where the limit will apply after the redact stage rather than before it.