Last active
January 21, 2023 16:34
-
-
Save Parassharmaa/6977c6552da6347d51f1692317d13ce6 to your computer and use it in GitHub Desktop.
Python script to export MongoDB collections to JSON file
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
import os | |
host = "" | |
username = "" | |
password = "" | |
directory_to_export = "" | |
database = "" | |
all_collections = [] | |
command = "mongoexport --host {} --username {} --password {} --db {} --collection {} --pretty --out {}/{}.json" | |
for c in all_collections: | |
os.system(command.format(host, username, password, database, c, directory_to_export, c)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment