For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.

MongoDB\Model\CollectionInfo::getName()

MongoDB\Model\CollectionInfo::getName()

Return the collection name.

function getName(): string

The collection name. This corresponds to the name field returned in the listCollections command reply.

<?php $db->createCollection('foo'); // Retrieves the collection nameforeach ($db->listCollections(['filter' => ['name' => 'foo']]) as $info) { echo $info->getName();}

The output would then resemble:

foo