Skip to content

Instantly share code, notes, and snippets.

@spolischook
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save spolischook/08ebf9462ad9eb2bdeed to your computer and use it in GitHub Desktop.

Select an option

Save spolischook/08ebf9462ad9eb2bdeed to your computer and use it in GitHub Desktop.
Batch script for import mongo dump
#!/usr/bin/env php
<?php
require_once __DIR__.'/base_script.php';
$options = getopt("", array('db:', 'dir:'));
$options['dir'] = !empty($options['dir']) ? $options['dir'] : "/";
$options['db'] = !empty($options['db']) ? $options['db']: "exercise";
$optionsLine = sprintf(" --dir=%s --db=%s", $options['dir'], $options['db']);
foreach (scandir($options['dir']) as $file) {
$pathParts = pathinfo($file);
if ('bson' === $pathParts['extension']) {
show_run(
'Import collection ' . $pathParts['filename'],
sprintf('mongorestore -d %s -c %s %s.bson', $options['db'], $pathParts['filename'], $options['dir'] . $pathParts['filename'])
);
}
}
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment