Reputation: 5169
I had made Id of document as MongoBinData object using annotation as
namespace Profile\UserBundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
/**
* User Document
*
*@MongoDB\Document(
* collection="Users",
* repositoryClass = "Profile\UserBundle\Document\UsersRepository"
* )
*
* @author ahmedhamdy
*/
class Users {
/**
*
* @var bin_uuid
*
* @MongoDB\Id(strategy = "UUID")
*
*/
protected $id;
/**
*
* @var string
*
* @MongoDB\Field(type = "string",name = "Email")
*
*/
protected $email;
//...
when i try to get object from MongoDB By email like :
$dm = $this->get('doctrine_mongodb')->getManager();
$user = $dm->getRepository('ProfileUserBundle:Users')->findOneBy(array(
'email' => '[email protected]',
));
var_dump($user);
then throw an Exception :
ContextErrorException: Warning: Illegal offset type in /var/www/xxxxx/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/UnitOfWork.php line 1544
Upvotes: 0
Views: 636
Reputation: 6922
This feature is currently being worked on in PR #444. The test cases introduced in that PR will also demonstrate how to use special types for an identifier field until we get a chance to write up new examples in the documentation.
Regarding conversion of MongoBinData to a string value, you should access the $bin
property instead of using MongoBinData::__toString(). The __toString()
method, which is also invoked when casting MongoBinData to a string, will return "<Mongo Binary Data>"
regardless of the binary data stored within.
Upvotes: 1