# Attempt to delete the database. This allows this to be used to recreate as well as create try: db = next((data for data in client.ReadDatabases() if data['id'] == db)) client.DeleteDatabase(db['_self']) print 'test database deleted' except: pass # Create database try: db = client.CreateDatabase({ 'id': db }) print 'test database created' except: pass # Create collection try: collection = client.CreateCollection(db['_self'],{ 'id': collectionName }) print 'restaurants collection created' except: pass #read the file with open(outfile) as f: for line in f: #upload this json document to the given collection jsondoc = json.loads(line) document = client.CreateDocument(collection['_self'],jsondoc) print 'one document uploaded' print 'done exporting'