Split export MongoDB to JSON

MongoDB 3 ก.พ. 2021

You could do this with a shell script and via the mongoexport options --skip and --limit so basically limit the number of documents in each file and use skip as an offset.

Something like this if your total is let say 5 milion records:

limit=10000;
skip=0;
for i in {1..500}; do mongoexport --db your_db --collection your_collection --type=json --fields "the fields you want to include in the export" --out exported_file.${i}.json -v --skip ${skip} --limit ${limit} --quiet;
let skip=$((skip+limit));
done

ref: https://stackoverflow.com/questions/28710652/split-export-mongodb-to-json

แท็ก

Onyx

Just a middle-aged programmer, Can do many things but not the most.