質問

been searching for an answer to this and found nothing so here is a little brain teaser for you.

How can I rename a collection using Doctrine? The docs give no support for renaming a collection or even cloning it but this is fairly straight forward functionality(to me anyway) and thought that there may very well be a good reason for not including it.

Cheers for any response, Neil

役に立ちましたか?

解決

After discussions with the Mongo PECL maintainers this functionality has not reached the pecl level yet. However there is still a silver lining.

Doctrine\MongoDb\Database has a command() method which allows you to do something similar to:

$mdb = ''; // Really it would be a mongo adapter
$db = new \Doctrine\MongoDB\Database(
    $mdb, // Our \Doctrine\MongoDB\Connection
    $mdb->selectDatabase('admin')->getMongoDB(),
    new \Doctrine\Common\EventManager()
);

$success = $db->command(array('renameCollection' => 'foo', 'to' => 'bar'));
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top