MongoCollection::__construct PHP Method

__construct() public method

Creates a new collection
public __construct ( MongoDB $db, string $name )
$db MongoDB Parent database.
$name string Name for this collection.
    public function __construct(MongoDB $db, $name)
    {
        $this->checkCollectionName($name);
        $this->db = $db;
        $this->name = (string) $name;
        $this->setReadPreferenceFromArray($db->getReadPreference());
        $this->setWriteConcernFromArray($db->getWriteConcern());
        $this->createCollectionObject();
    }

Usage Example

Beispiel #1
0
 /**
  * @param \MongoDB $db
  * @param string   $name
  * @param string   $documentClass
  */
 public function __construct(\MongoDB $db, $name, $documentClass = null)
 {
     if (isset($documentClass) && !is_a($documentClass, Entity::class, true)) {
         throw new \LogicException("Class {$documentClass} is not a " . Entity::class);
     }
     $this->documentClass = $documentClass;
     parent::__construct($db, $name);
 }
All Usage Examples Of MongoCollection::__construct