/** * @return \MongoDB\Collection */ private function createCollectionObject() { $options = ['readPreference' => $this->readPreference, 'writeConcern' => $this->writeConcern]; if ($this->collection === null) { $this->collection = $this->db->getDb()->selectCollection($this->name, $options); } else { $this->collection = $this->collection->withOptions($options); } }
/** * Creates a new collection * @link http://www.php.net/manual/en/mongocollection.construct.php * @param MongoDB $db Parent database. * @param string $name Name for this collection. * @throws Exception * @return MongoCollection */ public function __construct(MongoDB $db, $name) { $this->db = $db; $this->name = $name; $this->collection = $this->db->getDb()->selectCollection($name); }