Return type of $setIntersection

As per the course material / online help, $setIntersection will return an array. But, when I run $isArray: “$commonToBoth”, I am getting all false results.

Example code below:

db.movies.aggregate([
{
$project: {
_id: 0,
a: [“A”, “B”, “C” ],
b: [“B”, “D”],
}
},
{
$addFields: {
commonToBoth: {
$setIntersection: ["$a", “$b”]
},
types: {$isArray: “$commonToBoth”}
}
}
])

I expect the types to be “true” as the return value of $setIntersection is an array. But, I am getting all false. I want to retrieve the size of the array, commonToBoth.
Thank you.

I am not sure an added field is available in the addFields stage it is added. I would try to move that in another addFields stage.

Adding one more $addFields stage solved the problem. Thank you.