Example #1
0
 /**
  * Find a document by its id (_id)
  *
  * @param string|\MongoId $id
  * @return mixed
  * @throws Exception
  */
 public static function findById($id)
 {
     if (is_object($id) === false) {
         $collection = new self();
         $modelsManager = $collection->getModelsManager();
         //Check if the model use implicit ids
         $useImplicitIds = $modelsManager->isUsingImplicitObjectIds($collection);
         if ($useImplicitIds === true) {
             $id = new MongoId($id);
         }
     } elseif (is_string($id) === false) {
         throw new Exception('Invalid parameter type.');
     }
     return self::findFirst(array(array('_id' => $id)));
 }