0
我是面向文檔的數據庫的新手。我堅持一個簡單的問題:使用引用文檔的ID獲取父對象
我必須differents對象:後和標記。
{
"_id": "ObjectId("50dad56881000001")",
"author":"Chuck Norris",
"title":"Blah....",
"tags": [
DBRef("Tag", ObjectId("50dad564871000001")),
DBRef("Tag", ObjectId("50dad564871000002")),
DBRef("Tag", ObjectId("50dad564871000003"))
}
我需要通過標籤找到文章。我無法弄清楚如何做到這一點與被引用的對象的數組...
這裏是我的映射對象:
class Tag
{
/** @MongoDB\Id */
protected $id;
/** @MongoDB\Field(type="string") */
protected $name;
/** @MongoDB\Field(type="date") */
protected $createdAt;
}
class Article
{
/** @MongoDB\Id */
protected $id;
/** @MongoDB\Field(type="date") */
protected $date;
/** @MongoDB\Field(type="string") */
protected $title;
/** @MongoDB\Field(type="string") */
protected $author;
/** @MongoDB\Field(type="string") */
protected $content;
/** @MongoDB\ReferenceMany(targetDocument="Tag", cascade="all") */
protected $tags
}