Skip to content

Instantly share code, notes, and snippets.

@Parassharmaa
Last active January 21, 2023 16:34
Show Gist options
  • Save Parassharmaa/6977c6552da6347d51f1692317d13ce6 to your computer and use it in GitHub Desktop.
Save Parassharmaa/6977c6552da6347d51f1692317d13ce6 to your computer and use it in GitHub Desktop.
Python script to export MongoDB collections to JSON file
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