   simulateModifierUpdate: (doc, modifier) ->
     # TODO(aramk) If non-modifier properties are passed, this can result in them being merged at
     # times, though it should be throwing an error in mongo.
-    if Object.keys(modifier).length > 1 && !modifier.$set? && !modifier.$unset?
+    if _.keys(modifier).length > 1 && !modifier.$set? && !modifier.$unset?
       throw new Error('Unexpected keys in modifier.')
     tmpCollection = @createTemporary()
     doc = Setter.clone(doc)

      # Ensure no fields exist in $unset from $set.
      $unset = modifier.$unset
      if $unset
        _.each $set, (value, key) ->
          delete $unset[key]

####################################################################################################
# SCHEMAS

        updatedDoc = @simulateModifierUpdate(doc, modifier)
        Setter.merge(doc, updatedDoc)

    beforeUpdate = (userId, doc, fieldNames, modifier) ->
      updatedDoc = Collections.simulateModifierUpdate(doc, modifier)
      context = {userId: userId}
      # sanitizedDoc = Setter.clone(updatedDoc)
