- PHP 手册
- 函数参考
- 数据库扩展
- 针对各数据库系统对应的扩展
- Mongo
- 核心类
- MongoCollection
MongoCollection::getDBRef
(PECL mongo >=0.9.0)
MongoCollection::getDBRef — Fetches the document pointed to by a database reference
说明
public MongoCollection::getDBRef ( array$ref
) : array
参数
-
ref
-
A database reference.
返回值
Returns the database document pointed to by the reference.
范例
Example #1 MongoCollection::getDBRef() example
<?php
$playlists = $db->playlists;
$myList = $playlists->findOne(array('username' => 'me'));
// fetch each song in the playlist
foreach ($myList['songlist'] as $songRef) {
$song = $playlists->getDBRef($songRef);
echo $song['title'] . "\n";
}
?>
以上例程的输出类似于:
Dazed and Confused Ma na ma na Bohemian Rhapsody
In the above example each $songRef looks something like the following:
Array ( [$ref] => songs [$id] => 49902cde5162504500b45c2c )
参见
- MongoCollection::createDBRef() - 创建一个数据库引用
User Contributed Notes 1 note
up down 1 manuel at dziubas dot de ¶8 years ago
The "$id" has to be a
new MongoId("...")
in PHP driver!
Ref:
array(
"$ref" => "other_collection",
"$id" => new MongoId("the_referenced_dataobject_id")
)
add a note
官方地址:https://www.php.net/manual/en/mongocollection.getdbref.php