code: public function countBlockUsed($blockId)
      {
          $qb = $this->createQueryBuilder();
          $function = new \MongoCode(
              'function() {
                  for (var areaIndex in this.areas)
                      for (var key in this.areas[areaIndex].blocks)
                          if (this.areas[areaIndex].blocks[key].$id == "'.$blockId.'")
                              return this;
              }'
          );
          $qb->where($function);
  
          return $qb->getQuery()->execute()->count();
      }
docs: @param string $blockId
  
  @return boolean