public static boolean deleteDatabase ( final StitchAppClientInfo appInfo , final String serviceName , final EmbeddedMongoClientFactory clientFactory , final String userId ) { final String dataDir = appInfo . getDataDirectory ( ) ; if ( dataDir == null ) { throw new IllegalArgumentException ( "StitchAppClient not configured with a data directory" ) ; } final String instanceKey = String . format ( "%s-%s_sync_%s_%s" , appInfo . getClientAppId ( ) , dataDir , serviceName , userId ) ; final String dbPath = String . format ( "%s/%s/sync_mongodb_%s/%s/0/" , dataDir , appInfo . getClientAppId ( ) , serviceName , userId ) ; final MongoClient client = clientFactory . getClient ( instanceKey , dbPath , appInfo . getCodecRegistry ( ) ) ; for ( final String listDatabaseName : client . listDatabaseNames ( ) ) { try { client . getDatabase ( listDatabaseName ) . drop ( ) ; } catch ( Exception e ) { // do nothing } } client . close ( ) ; clientFactory . removeClient ( instanceKey ) ; return new File ( dbPath ) . delete ( ) ; }
Delete a database for a given path and userId .