【发布时间】:2017-09-14 10:30:31
【问题描述】:
我正在尝试使用 Symfony 中的一些引用创建 MongoDB 数据库。 在我的上下文中,我有 2 个文档 Customer 和 Meeting,One Customer 可以有 Many Meeting 以便我所做的:
Meeting.php
<?php
namespace FrontOfficeBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document
*/
class Meeting
{
/**
* @MongoDB\Id
* @MongoDB\ReferenceOne(targetDocument="Customer")
*/
protected $id;
/**
* @MongoDB\Field(type="timestamp")
*/
protected $creationDate;
...
Customer.php
<?php
namespace FrontOfficeBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* @MongoDB\Document
*/
class Customer
{
/**
* @MongoDB\Id()
* @MongoDB\ReferenceMany(targetDocument="Meeting")
*/
protected $id;
/**
* @MongoDB\Field(type="string")
*/
protected $username;
...
然后当我运行命令行时:
php bin/console 学说:mongodb:schema:update
我明白了:
没有为文档“FrontOfficeBundle\Document\Meeting”指定标识符/主键。每个文档都必须有一个标识符/主键。
我尝试使用 @MongoDB\UniqueIndex() 但没办法。 我认为 @MongoDB\Id 应该是一个标识符!!!
版本
- Symfony 3.2
- MongoDB 3.4.4
有什么想法吗?
谢谢。
【问题讨论】:
标签: mongodb symfony bidirectional