diff --git a/extensions/mongodb/ActiveRecord.php b/extensions/mongodb/ActiveRecord.php
index f157fd9..e60aab7 100644
--- a/extensions/mongodb/ActiveRecord.php
+++ b/extensions/mongodb/ActiveRecord.php
@@ -242,6 +242,7 @@ abstract class ActiveRecord extends BaseActiveRecord
         }
         $newId = static::getCollection()->insert($values);
         $this->setAttribute('_id', $newId);
+        $values['_id'] = $newId;
 
         $this->afterSave(true);
         $this->setOldAttributes($values);
diff --git a/extensions/mongodb/file/ActiveRecord.php b/extensions/mongodb/file/ActiveRecord.php
index 085db59..f67e815 100644
--- a/extensions/mongodb/file/ActiveRecord.php
+++ b/extensions/mongodb/file/ActiveRecord.php
@@ -147,6 +147,7 @@ abstract class ActiveRecord extends \yii\mongodb\ActiveRecord
             $newId = $collection->insert($values);
         }
         $this->setAttribute('_id', $newId);
+        $values['_id'] = $newId;
 
         $this->afterSave(true);
         $this->setOldAttributes($values);
diff --git a/framework/db/ActiveRecord.php b/framework/db/ActiveRecord.php
index a9b563c..c5f0c30 100644
--- a/framework/db/ActiveRecord.php
+++ b/framework/db/ActiveRecord.php
@@ -445,7 +445,7 @@ class ActiveRecord extends BaseActiveRecord
                 if ($this->getAttribute($name) === null) {
                     $id = $db->getLastInsertID($table->sequenceName);
                     $this->setAttribute($name, $id);
-                    $this->setOldAttribute($name, $id);
+                    $values[$name] = $id;
                     break;
                 }
             }
diff --git a/framework/db/BaseActiveRecord.php b/framework/db/BaseActiveRecord.php
index 0addba3..fbdc524 100644
--- a/framework/db/BaseActiveRecord.php
+++ b/framework/db/BaseActiveRecord.php
@@ -24,7 +24,8 @@ use yii\base\InvalidCallException;
  * @property array $dirtyAttributes The changed attribute values (name-value pairs). This property is
  * read-only.
  * @property boolean $isNewRecord Whether the record is new and should be inserted when calling [[save()]].
- * @property array $oldAttributes The old attribute values (name-value pairs).
+ * @property array $oldAttributes The old attribute values (name-value pairs). Note that the type of this
+ * property differs in getter and setter. See [[getOldAttributes()]] and [[setOldAttributes()]] for details.
  * @property mixed $oldPrimaryKey The old primary key value. An array (column name => column value) is
  * returned if the primary key is composite. A string is returned otherwise (null will be returned if the key
  * value is null). This property is read-only.
@@ -477,6 +478,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
      * Sets the old attribute values.
      * All existing old attribute values will be discarded.
      * @param array|null $values old attribute values to be set.
+     * If set to `null` this record is considered to be [[isNewRecord|new]].
      */
     public function setOldAttributes($values)
     {