With DocumentDB how do you limit the output of an aggregate pipeline?

0

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.

Ian
gefragt vor 7 Monaten50 Aufrufe
Keine Antworten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen