def AFTER_SETUP():
 admin.command('enablesharding', ShardMONGODB_DB)
 for (collection, keystr) in COLLECTION_KEYS.iteritems():
  key = SON(((k, 1) for k in keystr.split(',')))
  admin.command('shardcollection', ((ShardMONGODB_DB + '.') + collection), key=key)
 admin.command('shardcollection', (((ShardMONGODB_DB + '.') + GridFs_Collection) + '.files'), key={'_id': 1})
 admin.command('shardcollection', (((ShardMONGODB_DB + '.') + GridFs_Collection) + '.chunks'), key={'files_id': 1})
 for (k, v) in INDEX.items():
  for (key, kwargs) in v.items():
   conn[ShardMONGODB_DB][k].ensure_index((list(key) if (type(key) == types.TupleType) else key), **kwargs)

def AFTER_SETUP ( ) : admin . command ( 'enablesharding' , ShardMONGODB_DB ) for ( collection , keystr ) in COLLECTION_KEYS . iteritems ( ) : key = SON ( ( ( k , 1 ) for k in keystr . split ( ',' ) ) ) admin . command ( 'shardcollection' , ( ( ShardMONGODB_DB + '.' ) + collection ) , key = key ) admin . command ( 'shardcollection' , ( ( ( ShardMONGODB_DB + '.' ) + GridFs_Collection ) + '.files' ) , key = { '_id' : 1 } ) admin . command ( 'shardcollection' , ( ( ( ShardMONGODB_DB + '.' ) + GridFs_Collection ) + '.chunks' ) , key = { 'files_id' : 1 } ) for ( k , v ) in INDEX . items ( ) : for ( key , kwargs ) in v . items ( ) : conn [ ShardMONGODB_DB ] [ k ] . ensure_index ( ( list ( key ) if ( type ( key ) == types . TupleType ) else key ) , ** kwargs )
make index and shard keys .