             if not before.equals(record)
                 # there was an actual change, so update; doesn't change anything involving indexes.
                 changes = changes.add(@_primary_key_cols(record))
-                return new DBDoc(@_primary_keys, @_string_cols, @_records.set(n, record), @_everything, @_indexes, changes)
+                return new DBDoc(@_primary_keys, @_string_cols, @_records.set(n, record), @_everything, @_indexes, {changes:changes, from_db:@_changes.from_db})
             else
                 return @
         else


        everything = @_everything.subtract(remove)

        return new DBDoc(@_primary_keys, @_string_cols, records, everything, indexes, changes)

    # Returns immutable list of all matches
    get: (where) =>

            # is already closed and nobody is listening.
            # See https://github.com/sagemathinc/smc/issues/1829
            return
        db = @_doc.get_doc()._db
        if not @_last_db?
            # first time ever -- just get all keys
            changes = db.changed_keys()
        else
            # may be able to use tracked changes...
            {changes, from_db} = @_doc.get_doc().changes()
            @_doc.get_doc().reset_changes()
            if from_db != @_last_db
                # NOPE: have to compute the hard (but rock solid and accurate) way.
                changes = db.changed_keys(@_last_db)

        if changes.size > 0 or @_first_change_event  # something actually probably changed
            @emit('change', changes)
        @_last_db = db
        delete @_first_change_event

    close: () =>
