Improve null handling in Query.prototype._castUpdate

Query.prototype._castUpdate assumes that property values of obj are
non-null when checking the constructor of the value.  This will cause a
TypeError when the values are null, which can legitimately occur during
an update with the overwrite option.  Handle this case by checking if
the value is truthy before checking the name of the constructor.

Signed-off-by: Kevin Locke <klocke@quantpost.com>
Merge pull request #2154 from kevinoid/cast-update-null-fix

TypeError when updating a document with null properties
Fix #1874
Fix #2019
removed duplicate require statement
In Model.update() using merge function for conditions
Merge pull request #2171 from esco/3.8.x

removed duplicate require statement
Fix #2123: aggressively remove _id after populate with select _id:0
POC for fixing #2159
Fix #2159: make sure to remove old events when creating new documentarray
Merge pull request #2173 from Mikxail/3.8.x

In Model.update() using merge function for conditions
Fix #2127
Fix #2144
Make unit test compatible with mocha async-only
Hack to make findOneAndUpdate with __v work with mongodb 2.2
release 3.8.13
Now working on 3.8.14
Fix #2002: get rid of bad hack for converting MongooseArray -> string
Fix #2035: slightly nasty hack to work around toObject messiness
Fix `mongoose.models` consistency bug.

Since `mongoose.models` and `mongoose.connection.models` weren't the
same object, calling `doc.db.modelNames()` didn't return the same output
as calling `mongoose.modelNames()` even if `doc` was an instance of a
`Model` registered to the default connection.

This caused weird problems when using discriminators, since they are
registered with `parentModel.db.model(...)` (which is equal to
`mongoose.connection`) rather than with `mongoose.model(...)`. Using
discriminators, `mongoose.models` ended up having the parent models'
references, while `mongoose.connection.models` had the discriminators
references.

The fix was to set the default connection's `models` property to
`mongoose.models` so that they share the same object. This makes
`mongoose.models` and `mongoose.connection.models` (or
`document.db.models`, `model.db.models`, `model.base.models` etc.)
deterministically equal.