我想检查一下ArangoDB是否已经存在一个集合。
$collectionHandler = new CollectionHandler($arango);
$userCollection = new Collection();
$userCollection->setName('_profiles');因为我得到了以下错误:
Server error: 1207:cannot create collection: duplicate name cannot create collection: duplicate name如何检查ArangoDB是否已经存在一个集合?
发布于 2014-10-27 16:59:45
我应该使用try/catch语句
try {
$collectionHandler = new CollectionHandler($arango);
$userCollection = new Collection();
$userCollection->setName('_profiles');
$collectionHandler->create($userCollection);
} catch (ServerException $e) {
// do something
}发布于 2017-02-02 10:21:33
使用异常处理来驱动程序流被认为是不好的风格--它应该用于真正的异常。在您的示例中,我认为包含用户配置文件的集合的存在是规则,而不是例外。
检查集合是否存在的正确方法是CollectionHandler::has($id)。创建集合的正确方法是使用CollectionHandler::create($collection)。create接受一个字符串作为参数,即要创建的集合的名称。
$userCollectionName = '_profiles';
$collectionHandler = new CollectionHandler($arango);
$userCollection = $collectionHandler->has($userCollectionName) ?
$collectionHandler->get($userCollectionName)
:
$collectionHandler->create($userCollectionName);https://stackoverflow.com/questions/26590106
复制相似问题