I must protest the wording of the final

In question 2 one of the choices is

  • Pipeline 2 fails because $divide operator only supports numeric types

And in the documentation on $divide it says:

The arguments can be any valid expression as long as they resolve to numbers.

In the example given, the field named “a” is an array of numbers. So how does this not “resolve to numbers”?

@Jason_Hernandez Maybe the docs should be more informative,

An array does not resolve to numbers, it can be tested in the shell:

“errmsg” : “$divide only supports numeric types, not array …”,

Not even this ["$array.index", 5] (only works for document fields, afaik)

But an expression like this will:

$divide:[{$arrayElemAt:[<array>, <index>]}, 5]

Think I failed one of those too :joy:

1 Like

@Jason_Hernandez This was tricky for me too, I had same doubt and I had to do a quick test before answering the question. $divide takes only number type data, so learnt that [1,2,3] is not a number but an array type data.

Hi all,

If you get similar doubts, it is always good to test it in the mongo shell. This will help you in understanding the concepts.

Please feel free to reach out if you have any questions.

Kind Regards,