The only way I found to do this is:
$mongo->selectDB('new_db')->createCollection('tmp_collection');
$mongo->selectDB('new_db')->dropCollection('tmp_collection');
Doing just $mongo->selectDB('new_db')
actually doesn't work.
Got any idea?
You'll need to run at least one command on the Database before it is created ...
This command can be run before you add any Collections ... so you can merely list (the nonexistent) Collections.
<?php
$connection = new Mongo();
$db = $connection->foo;
$list = $db->listCollections();
foreach ($list as $collection) {
echo "$collection </br>";
}
?>
Your new Database should now exist, with no user Collections created yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With