ekfioq
Last Updated: February 25, 2016
·
633
· peterpay

mongoDB easy db creation php

To create a db on runtime from php:

$conn = new Mongo('serverConnectionString');

create a db

$db = $conn->selectDB("dbName"); 

on the first command like adding a collection to that db will trigger the creation

$db->command(array("create" =>"newCollectionName")); 

also security sometime is needed so :

$db->selectCollection("system.users"); 
$db->insert(array('user' =>"username", 'password'=> md5('password'),'readOnly' => false));