     if updatedBy
       definition[updatedBy] =
         autoValue: ->
-          unless @isFromTrustedCode
+          if @isFromTrustedCode and @isUpdate and not @isSet
+            '0'
+          else
             if @isUpdate
               @userId
             else


        denyInsert: true
        optional: true
        regEx: SimpleSchema.RegEx.Id
        type: String

    @attachSchema new SimpleSchema definition

  else
    @before.insert (userId, doc) ->
      if createdAt
        doc[createdAt] = new Date
      if createdBy
        doc[createdBy] = userId

    @before.update (userId, doc, fieldNames, modifier, options) ->
      $set = modifier.$set

      unless $set
        $set = {}

      if updatedAt
        $set[updatedAt] = new Date

      if updatedBy
        $set[updatedBy] = userId

CollectionBehaviour.define 'timestampable', behaviour

    if createdBy
      definition[createdBy] =
        autoValue: ->
          if @isFromTrustedCode and not @isSet
            '0'
          else
            if @isInsert
              @userId
            else if @isUpsert
