Exam: Question 2 Understanding of word fail in this context

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

Fails – can be interpreted in several ways

a) Fails: you will not get a result document output
b) Fails: you will not get a result document with a correct value (failed)
c) The pipeline as such before running has a failure as it is not consistent to the specs

What kind of failure(s) do you mean here?

@ Rene_DoIT

The meaning of “fail” here is fairly straightforward. If you attempt to run the indicated $aggregation pipeline, you will get an error. Try it.

Hi David

I tried it on my system with Mongo v4.0.5. It run well. Meaning I have received a document with no error announced but the result return value in the document was a null.

I expected that it will not run through and give an error.

@ Rene_DoIT

No, it doesn’t. Remember a couple of setup issues. First of all, you need to create the indicated collection. Here’s how I did it from the shell

use m121
db.testcollection.insertOne( { "a": [1, 34, 13]  }  )

now check that you have set it up correctly:

db.testcollection.find()

should return something like

{ "_id" : ObjectId("5c50a1bd2f93d04ec2da131b"), "a" : [ 1, 34, 13 ] }

Now run the indicated $aggregation pipeline

db.testcollection.aggregate([
    {"$project": { "a_divided" : {"$divide": ["$a", 1]}  }}
])

This fails on all versions of MongoDB that I have (3.2 – 4.0). Try it again. I think you’ve made a mistake in your setup.