I need to restore MongoDB which was sharded on dev env.
Before starting restore I need to build build indexes and enable sharding on collection so that when DB is restored collections get sharded.
To accomplish that I need to build index on collection dynamically
How to build index using LIST which will be passed as first para to pymongo create_index(key_or_list, deprecated_unique=None, ttl=300, **kwargs)
I have following JSON file in which index info is stored.
{"_id": "client_415.reviews", "key": {"year": 1.0, "state": 1.0}, "unique": false}
client = MongoClient(URI,port)
client.admin.command('enableSharding', dbname)
db = client[dbname]
col =db[CollectionName] ## Collection Name will be "reviews"
json_data = f.read()
loaded_json = json.loads(json_data)
col.create_index(LISTName)
# it should form something like create_index([('year',1),('state',1) ], unique = false)
Now how should I build LIST to pass to create_index ??
Thanks for looking into it.
DK