Basic-updates.spec.js - using `projection` key word or not

In M220JS, test/lessons/basic-updates.spec.js, after line 80, if we do a console.log() of newTheaterAddress we get the whole object despite the fact {"location.address.street1": 1 } was passed as the projection in the theaters.findOne() call.

Did passing {"location.address.street1": 1 } as projection failed to do so?

If we pass the proper { projection: { "location.address.street1": 1 } } instead we do get what is expected though.

Would someone please shed some light here.


Yes this is old syntax and basically to bring things in line across ALL implemented drivers the projection key should be used instead.

The legacy reason is that older API implementation allowed this without the keyword in some languages ( the NodeJS driver was one ) and essentially inspected the second argument to see if it was just a “projection” or some other set of options instead.

The course video content however does demonstrate the correct syntax with the projection keyword in the options argument.

NOTE - This example is for findOne(), yet in later exercises in the course material you need to implement something similar for thefind() method. That method returns a Cursor on which there is a different way to “project” the fields you want to return.