سؤال

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