对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Make the MongoDB docs better! We value your opinion. Share your feedback for a chance to win $100.
MongoDB Branding Shape
Click here >
Docs 菜单

MongoDB\Collection::getDatabaseName()

MongoDB\Collection::getDatabaseName()

返回包含此集合的数据库的名称。

function getDatabaseName(): string

包含此collection的数据库的名称(字符串形式)。

以下返回test数据库中zipscollection的数据库名称。

<?php
$collection = (new MongoDB\Client)->test->zips;
echo $collection->getDatabaseName();

而输出将类似如下所示:

test