Created
March 8, 2023 16:23
-
-
Save toniher/6bfc8f517ccd7278144ac3534d79a694 to your computer and use it in GitHub Desktop.
Fast processing of a CouchDB json import file. Related to this: https://simeon-yan-iliev.medium.com/export-import-a-database-with-couchdb-74bfec3831bc
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 | |
import sys | |
import json | |
if len(sys.argv) != 2: | |
exit() | |
print("{\"docs\": [") | |
with open(sys.argv[1]) as infile: | |
next(infile) | |
for line in infile: | |
line = line.rstrip() | |
if line.startswith("{\"id"): | |
doc = json.loads(line.rstrip(",")) | |
# Instead of specific values, if all doc, we could simply remove _rev below | |
struct = {"_id": doc["doc"]["_id"], "off": doc["doc"]["off"]} | |
end = "" | |
if line.endswith(","): | |
end = "," | |
print(json.dumps(struct) + end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment