title: how to fix the Invalid Object ID Mongo Exception
body: <p>I have this code</p>
  
  <pre><code>public function deactivateDuplicateDevices(Document\Device $oDevice, Document\Passenger $oPassenger)
  {
      $passengerId = new \MongoId(oPassenger-&gt;getId());
      $deviceId = new \MongoId($oDevice-&gt;getId());
  
      return $this-&gt;createQueryBuilder('Device')
          -&gt;update()
          -&gt;multiple(true)
          -&gt;field('activated')-&gt;set(false)
          -&gt;field('passenger')-&gt;unsetField()-&gt;equals($passengerId)
          -&gt;field('_id')-&gt;notEqual($deviceId)
          -&gt;getQuery()
          -&gt;execute();
  }
  </code></pre>
  
  <p>which works just fine on my dev server but crashes on my local machine. </p>
  
  <p>running <code>pecl list</code> on dev returns</p>
  
  <pre><code>APC     3.1.13  beta
  amqp    1.2.0   stable
  intl    3.0.0   stable
  mongo   1.3.7   stable
  </code></pre>
  
  <p>and on local returns:</p>
  
  <pre><code>mongo   1.5.6   stable
  xdebug  2.2.5   stable
  </code></pre>
  
  <p>the crash message on my machine is</p>
  
  <pre><code>"name":"MongoException","message":"Invalid object ID"},"code":500}
  </code></pre>
  
  <p>I'v tried downgrading my local version of mongo but i couldn't figure it out with pecl's poor documentation. for example i tried this:</p>
  
  <pre><code>sudo pecl upgrade -f -c channel://pecl.php.net/mongo-1.3.7
  </code></pre>
  
  <p>but i keep on getting <code>channel does not exist</code> for all my channel permutations.</p>
  
  <p>also running <code>mongod --version</code> locally returns <strong>db version v2.6.0</strong> and on dev returns <strong>db version v2.4.3</strong></p>
  
  <p>this is the full stack trace</p>
  
  <pre><code>{"response":{"file":"\/Users\/abdullah\/dev\/php\/smartTaxi\/vendor\/doctrine\/mongodb-odm\/lib\/Doctrine\/ODM\/MongoDB\/Mapping\/Types\/IdType.php","line":37,"trace":"#0 \/Users\/abdullah\/dev\/php\/smartTaxi\/vendor\/doctrine\/mongodb-odm\/lib\/Doctrine\/ODM\/MongoDB\/Mapping\/Types\/IdType.php(37): MongoId-&gt;__construct(1)\n#1 \/Users\/abdullah\/dev\/php\/smartTaxi\/vendor\/doctrine\/mongodb-odm\/lib\/Doctrine\/ODM\/MongoDB\/Mapping\/ClassMetadataInfo.php(1291): Doctrine\\ODM\\MongoDB\\Mapping\\Types\\IdType-&gt;convertToDatabaseValue(1)\n#2 \/Users\/abdullah\/dev\/php\/smartTaxi\/vendor\/doctrine\/mongodb-odm\/lib\/Doctrine\/ODM\/MongoDB\/Persisters\/DocumentPersister.php(990): Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadataInfo-&gt;getDatabaseIdentifierValue(1)\n#3 \/Users\/abdullah\/dev\/php\/smartTaxi\/vendor\/doctrine\/mongodb-odm\/lib\/Doctrine\/ODM\/MongoDB\/Persisters\/DocumentPersister.php(861): Doctrine\\ODM\\MongoDB\\Persisters\\DocumentPersister-&gt;prepareQueryElement('passenger', 1, NULL, true)\n#4 \/Users\/abdullah\/dev\/php\/smartTaxi\/vendor\/doctrine\/mongodb-odm\/lib\/Doctrine\/ODM\/MongoDB\/Persisters\/DocumentPersister.php(836): Doctrine\\ODM\\MongoDB\\Persisters\\DocumentPersister-&gt;prepareSubQuery(Array)\n#5 \/Users\/abdullah\/dev\/php\/smartTaxi\/vendor\/doctrine\/mongodb-odm\/lib\/Doctrine\/ODM\/MongoDB\/Query\/Expr.php(129): Doctrine\\ODM\\MongoDB\\Persisters\\DocumentPersister-&gt;prepareNewObj(Array)\n#6 \/Users\/abdullah\/dev\/php\/smartTaxi\/vendor\/doctrine\/mongodb-odm\/lib\/Doctrine\/ODM\/MongoDB\/Query\/Builder.php(239): Doctrine\\ODM\\MongoDB\\Query\\Expr-&gt;getNewObj()\n#7 \/Users\/abdullah\/dev\/php\/smartTaxi\/src\/St\/AppBundle\/Repository\/DeviceRepository.php(132): Doctrine\\ODM\\MongoDB\\Query\\Builder-&gt;getQuery()\n#8 \/Users\/abdullah\/dev\/php\/smartTaxi\/src\/St\/AppBundle\/Model\/PassengerManager.php(207): St\\AppBundle\\Repository\\DeviceRepository-&gt;deactivateDuplicateDevices(Object(St\\AppBundle\\Document\\Device), Object(MongoDBODMProxies\\__CG__\\St\\AppBundle\\Document\\Passenger))\n#9 \/Users\/abdullah\/dev\/php\/smartTaxi\/src\/St\/ApiBundle\/Controller\/PassengerController.php(96): St\\AppBundle\\Model\\PassengerManager-&gt;register(Object(St\\AppBundle\\Document\\Device), '6651')\n#10 [internal function]: St\\ApiBundle\\Controller\\PassengerController-&gt;verifyRegistrationAction()\n#11 \/Users\/abdullah\/dev\/php\/smartTaxi\/vendor\/jms\/cg\/src\/CG\/Proxy\/MethodInvocation.php(63): ReflectionMethod-&gt;invokeArgs(Object(EnhancedProxy_5e2a7e5669a027f8d79b4b96c7288b294d024637\\__CG__\\St\\ApiBundle\\Controller\\PassengerController), Array)\n#12 \/Users\/abdullah\/dev\/php\/smartTaxi\/vendor\/jms\/security-extra-bundle\/JMS\/SecurityExtraBundle\/Security\/Authorization\/Interception\/MethodSecurityInterceptor.php(120): CG\\Proxy\\MethodInvocation-&gt;proceed()\n#13 \/Users\/abdullah\/dev\/php\/smartTaxi\/vendor\/jms\/cg\/src\/CG\/Proxy\/MethodInvocation.php(58): JMS\\SecurityExtraBundle\\Security\\Authorization\\Interception\\MethodSecurityInterceptor-&gt;intercept(Object(CG\\Proxy\\MethodInvocation))\n#14 \/Users\/abdullah\/dev\/php\/smartTaxi\/app\/cache\/dev\/jms_diextra\/proxies\/St-ApiBundle-Controller-PassengerController.php(21): CG\\Proxy\\MethodInvocation-&gt;proceed()\n#15 [internal function]: EnhancedProxy_5e2a7e5669a027f8d79b4b96c7288b294d024637\\__CG__\\St\\ApiBundle\\Controller\\PassengerController-&gt;verifyRegistrationAction()\n#16 \/Users\/abdullah\/dev\/php\/smartTaxi\/app\/bootstrap.php.cache(1426): call_user_func_array(Array, Array)\n#17 \/Users\/abdullah\/dev\/php\/smartTaxi\/app\/bootstrap.php.cache(1390): Symfony\\Component\\HttpKernel\\HttpKernel-&gt;handleRaw(Object(Symfony\\Component\\HttpFoundation\\Request), 1)\n#18 \/Users\/abdullah\/dev\/php\/smartTaxi\/app\/bootstrap.php.cache(1566): Symfony\\Component\\HttpKernel\\HttpKernel-&gt;handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#19 \/Users\/abdullah\/dev\/php\/smartTaxi\/app\/bootstrap.php.cache(617): Symfony\\Bundle\\FrameworkBundle\\HttpKernel-&gt;handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#20 \/Users\/abdullah\/dev\/php\/smartTaxi\/web\/app_dev.php(31): Symfony\\Component\\HttpKernel\\Kernel-&gt;handle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#21 \/Users\/abdullah\/dev\/php\/smartTaxi\/vendor\/symfony\/symfony\/src\/Symfony\/Bundle\/FrameworkBundle\/Resources\/config\/router.php(30): require('\/Users\/abdullah...')\n#22 {main}","name":"MongoException","message":"Invalid object ID"},"code":500}
  </code></pre>
  
  <p>in php storm if i highlight the mongoid type it shows me this</p>
  
  <p><img src="https://i.stack.imgur.com/oU4wP.png" alt="enter image description here"></p>
  
  <p>ideas?</p>