Skip to content

Instantly share code, notes, and snippets.

@MrCreosote
Last active November 25, 2021 02:31
Show Gist options
  • Save MrCreosote/8fd87d314fa76b6807b1fc7bd6490bdb to your computer and use it in GitHub Desktop.
Save MrCreosote/8fd87d314fa76b6807b1fc7bd6490bdb to your computer and use it in GitHub Desktop.
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