For AI agents: a documentation index is available at https://www.mongodb.com/es/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
MongoDB Branding Shape
Click here >
Docs Menu

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 name
foreach ($db->listCollections(['filter' => ['name' => 'foo']]) as $info) {
echo $info->getName();
}

The output would then resemble:

foo