Last active
November 25, 2021 02:31
-
-
Save MrCreosote/8fd87d314fa76b6807b1fc7bd6490bdb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
import sys | |
from pymongo.mongo_client import MongoClient | |
WS_MONGO_PWD = 'WS_MONGO_PWD' | |
MONGO_COL_WSOBJS = 'workspaceObjVersions' | |
def get_ws_obj_collection(): | |
_, host, db, user = sys.argv | |
pwd = os.environ[WS_MONGO_PWD] | |
client = MongoClient(host, authSource=db, username=user, password=pwd) | |
client.admin.command('ismaster') # check connection | |
return client[db][MONGO_COL_WSOBJS] | |
def printobj(nonemeta, o, kv): | |
print(f'{nonemeta}, {o["ws"]}, {o["id"]}, {o["ver"]}, {o["savedate"]}, {o["type"]}, {kv["k"]}, {kv["v"]}') | |
def main(): | |
col = get_ws_obj_collection() | |
count = 0 | |
for o in col.find(): | |
meta = o.get('meta') | |
if meta: | |
for kv in meta: | |
# type field still exists at this time | |
if kv['k'] is None or kv['v'] is None: | |
printobj(1, o, kv) | |
elif len(kv['k']) + len(kv['v']) > 900: | |
printobj(0, o, kv) | |
count += 1 | |
if count % 1000 == 0: | |
print(count, file=sys.stderr) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment