'MongoDB - how can I pass variable or expression to $limit aggregation pipeline?

I use this expression for limiting the number of documents, but Mongo seems not accept it (in the official document, $limit only allow Integer value). But is there any tricks to get it?

{ $limit: '$numQuestion', },


Solution 1:[1]

So you mean this?

numQuestion = 10;
{ $limit: numQuestion  },

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wernfried Domscheit