i have a problem fetching data with doctrine-mongodb bundle. If i use the "protected" access modifier for the document's fields, the fetched objects are empty. Here is an example of the class:
<?php
namespace App\Document;
use App\Repository\FingerprintRepository;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
#[MongoDB\Document(collection: "fingerprint")]
class Fingerprint
{
#[MongoDB\Id(strategy: "AUTO")]
protected string $id;
#[MongoDB\Field(type: 'string')]
protected string $fingerprint;
public function getId(): string
{
return $this->id;
}
public function setId($id): self
{
$this->id = $id;
return $this;
}
public function getFingerprint(): string
{
return $this->fingerprint;
}
public function setFingerprint($fingerprint): self
{
$this->fingerprint = $fingerprint;
return $this;
}
}
But if i change the field's access modifier to "public" then the document is correctly hydrated. I'm using the following software:
- PHP 8.1
- Symfony 6.3
- doctrine/mongodb-odm 2.5.2
- doctrine/mongodb-odm-bundle 4.4.3