arangodbarangodb-php

ArangoDB-PHP Collection exists check


I want to make a check if a Collection already exist with ArangoDB-PHP.

$collectionHandler = new CollectionHandler($arango);
$userCollection = new Collection();
$userCollection->setName('_profiles');

Because I get the following error:

Server error: 1207:cannot create collection: duplicate name cannot create collection: duplicate name

How can I check if a collection already exists with ArangoDB-PHP?


Solution

  • I should use try/catch statement

    try { 
        $collectionHandler = new CollectionHandler($arango);
        $userCollection = new Collection();
        $userCollection->setName('_profiles');
        $collectionHandler->create($userCollection);
    } catch (ServerException $e) {
        // do something
    }