I dont understand why i get null

why i get this error message: MongoServerError: The argument to $size must be an array, but was of type: null


Hi @Febrian_Pratama_Putr,
Please note that favorites is not a field in any of the documents.
But favorites is a variable that you have declared in the MongoDB shell that can be used as a reference to the array.
Hence $favorites would not work and will always return null.
Therefore, if you want to use that variable in your aggregation pipeline, you can simply use it by mentioning it in the following manner:

“num_favs”:{ $size:{ $setIntersection:["$cast", favorites] } }

I hope it helps.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer