You could have PHP create all of the shell commands beforehand and then run them all at once:
$collections = array('color', 'shape', 'size');
$command = '';
foreach($collections as $collection) {
$command .= 'mongoimport --db test --collection ' . $collection . ' --file ' . $collection . '.json; ';
}
shell_exec($command);
This eliminates multiple calls to shell_exec()
. However, perhaps mongoimport
is available in the PHP mongo API.