Using $size in a matches for a $gt


So I have tried a few variations, since I would not like to use a $project.

{$match: {“languages”: {$size: {$gt: 0 } } }

However it keeps throwing up an issue. It seems a pretty simple thing to do, since arrays are such a basic tenant of the document.

In one of the labs, I just wanted to test that I was looking at language arrays with with than one element. I know I can do a simple $size: 2. Any thoughts :slight_smile:


As an aggregation operator, $size requires an array (or any expression that returns an array). I believe the way to go is to use a projection or $addFields before the match stage.

José Carlos


I appreciate that the limitations of the form, it just seems a bit clunky not to have the ability.

Maybe a $size: 1+ (for greater than or equal to 1), and vice versa for 1-, though -1- for less than or equal -1 would be amusing :slight_smile:

Thank you