yii\mongodb\Connection::getCollection PHP Method

getCollection() public method

Returns the MongoDB collection with the given name.
public getCollection ( string | array $name, boolean $refresh = false ) : Collection
$name string | array collection name. If string considered as the name of the collection inside the default database. If array - first element considered as the name of the database, second - as name of collection inside that database
$refresh boolean whether to reload the collection instance even if it is found in the cache.
return Collection Mongo collection instance.
    public function getCollection($name, $refresh = false)
    {
        if (is_array($name)) {
            list($dbName, $collectionName) = $name;
            return $this->getDatabase($dbName)->getCollection($collectionName, $refresh);
        } else {
            return $this->getDatabase()->getCollection($name, $refresh);
        }
    }

Usage Example

示例#1
0
 protected function doBatchSave($name, $rows)
 {
     \Yii::trace("Batch save to '{$name}'", __METHOD__);
     $this->db->getCollection($name)->batchInsert($rows);
 }