pythonarangodbpyarango

Rename collection with pyArango


I'm trying to rename a ArangoDB collection using pyArango. This is what I have so far:

connection = pyArango.Connection('http://random-address', username='random-username', password='random-password')
test_db = Database(connection, 'test-db')
collection = test_db["new"]
collection.action("PUT", "rename", name="newname")

The code fails in line 4:

{'error': True, 'code': 400, 'errorNum': 1208, 'errorMessage': 'name must be non-empty'}

I'm probably using the action method incorrectly but the documentation does not provide any examples. Anybody got an idea?


Solution

  • I've fixed it like this:

    def rename_collection(arango_uri, username, password, database, collection, new_name):
        url = '{}/_db/{}/_api/collection/{}/rename'.format(arango_uri, database, collection)
        params = {"name": new_name}
        response = requests.put(url, data=json.dumps(params), auth=HTTPBasicAuth(username, password))
        return response