I have two Documents: Client and PV. Many PV are referenced in one Client. It's unidirectional.
Client
/**
* @MongoDB\Document
*/
class Client
{
/**
* @MongoDB\Id(strategy="auto")
*/
protected $id;
/**
* @MongoDB\String
*/
protected $name;
/**
* @MongoDB\ReferenceMany(targetDocument="PV", simple=true, cascade={"persist", "remove"})
*/
private $PV = array();
public function __construct()
{
$this->PV = new \Doctrine\Common\Collections\ArrayCollection();
}
}
PV
/**
* @MongoDB\Document
*/
class PV
{
/**
* @MongoDB\Id(strategy="auto")
*/
protected $id;
/**
* @MongoDB\String
*/
protected $name;
}
To fetch a Client Document I use:
$client = $this->get('doctrine_mongodb')
->getRepository('HubMainBundle:Client')
->findOneById($id);
And I get:
"53da113176a2955c6d8b4567": {
"id": "53da113176a2955c6d8b4567",
"name": "Test",
"_p_v": [
{
"id": "53da121276a2956c708b4568",
"name": "test pv"
},
{
"id": "53da4e2876a295b7088b4567",
"name": "pv 2"
}
]
}
But I want:
"53da113176a2955c6d8b4567": {
"id": "53da113176a2955c6d8b4567",
"name": "Test",
"_p_v" : [
"53da121276a2956c708b4568",
"53da4e2876a295b7088b4567"
]
}
So how can I fetch just the Parent Document with MongoIds for every PV referenced not the entires referenced PVs ? (In MongoDB when I do db.Client.find({name: 'Test'})
I got the MongoIds not the documents).
Is it related to the Doctrine MongoDB hydrator ?