MongoCollection::createDBRef

Creates a database reference

&reftitle.description; public `array` `MongoCollection::createDBRef` `mixed` `document_or_id`
&reftitle.parameters;

`document_or_id`

- If an array or object is given, its `_id` field will be used as the reference ID. If a `MongoId` or scalar is given, it will be used as the reference ID.

&reftitle.returnvalues;

Returns a database reference array.

If an array without an `_id` field was provided as the `document_or_id` parameter, &null; will be returned.

&reftitle.examples;

### `MongoCollection::createDBRef` example

    <?php

    $songs = $db->songs;
    $playlists = $db->playlists;

    // create a reference to a song
    $manamana = $songs->findOne(array('title' => 'Ma na ma na'));
    $refToSong = $songs->createDBRef($manamana);

    // add the reference to my playlist
    $playlists->update(array('username' => 'me'), array('$push' => array('songlist' => $refToSong)));

    ?>

&reftitle.seealso;

- `MongoCollection::getDBRef`