Using Cursor-like Stages

Doing $addFields with the below expression in Compass on the movie collection

fab:{ $setIntersection: [[“Erik Lindholm”, “Aron Lindgren”] , “$cast” ]}

getting correct results

In next $addFields stage I have -

fab_num: {$size:fab}

getting error -

Expected “[” or AggregationStage but “{” found.

What wrong am I doing?


  • the error message should tell you what line the syntax error originated from
  • this particular error is not within this fab_num: {$size:fab}
  • in addition to this error, you will encounter another parse error within this fab_num: {$size:fab}. Here’s a screenshot from the documentation (hopefully you can spot the difference):

There is no line number. I did it in Compass. See the screenshot attached.

I changed from $size:fab to $size:"$fab". Now ther is a different error-

Expected “[” or AggregationStage but “{” found.


The new error message is telling you exactly what the problem is. Have a think.

I have no clue. Please provide a hint.

Hint: It’s a data problem. The syntax is fine.

It worked after I added a check for NULL. Thank you.

Could you please tell the difference between -

“num_fab” : 1
“num_fab” : {"$eq":1}

The first match works, but the second does not without throwing any error.

:arrow_up: :question:

Shows “No preview available”

They are equivalent. Share screenshots of both for comparison.

PFA screenshots.

I do not think that &eq is a valid operator.