/** * Insert a new record and get the value of the primary key. * * @param array $values * @param string $sequence * @return int */ public function insertGetId(array $values, $sequence = null) { $result = $this->collection->InsertOne($values); if (1 == (int) $result->isAcknowledged()) { if (is_null($sequence)) { $sequence = '_id'; } // Return id return $sequence == '_id' ? $result->getInsertedId()->__toString() : $values[$sequence]; } }