Last active
January 4, 2016 16:48
-
-
Save danohu/8649383 to your computer and use it in GitHub Desktop.
split large mongodumps into files usable for import
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from itertools import izip_longest | |
import json | |
import subprocess | |
import sys | |
def grouper(iterable, n, fillvalue=None): | |
args = [iter(iterable)] * n | |
return izip_longest(fillvalue=fillvalue, *args) | |
def split_pretty_array(infh, outfilebase, numperfile): | |
for i, group in enumerate(grouper(json.loads(infh), numperfile, '')): | |
with open('%s_%s.json' % (outfilebase, i), 'w') as outputfile: | |
json.dump(group, outputfile) | |
if __name__ == '__main__': | |
split_pretty_array(sys.stdin, sys.argv[1], 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment