public function getDocument()
{
if (!is_array($this->_document)) {
if (is_scalar($this->_document) || $this->_document instanceof ObjectID) {
$document = $this->collection->findOne(['_id' => $this->_document]);
if (empty($document)) {
throw new InvalidConfigException('Document id=' . $this->_document . ' does not exist at collection "' . $this->collection->getFullName() . '"');
}
$this->_document = $document;
} else {
$this->_document = (array) $this->_document;
}
}
return $this->_document;
}