简体   繁体   中英

doctrine-mongoDB - ContextErrorException: Warning: Illegal offset

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' => 'xxxx@hotmail.com',
                ));
   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
  • How to work with MongoBinData object ???
  • how to insert new Users object with id from type MongoBinData object ??
  • is there any way to convert MongoBinData object to string ??

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM