Closed igaln closed 4 years ago
in pyArango/database.py
there is a method Database().hasCollection(name): bool
. You could also call Database().reloadCollections()
first to ensure you have the latest collection set loaded into the client.
Something like:
from pyArango.connection import Connection
conn = Connection(**params)
sess = conn[DB_NAME]
#sess.reloadCollections()
if sess.hasCollection(name):
return sess.collections[name]
return sess.createCollection(name)
As @subfxnet pointed out you could use the hasCollection(
try:
DB[col_name]
except KeyError:
print("collection not found")
Trying to check if a collection exists before creating
Options
These seems to an isCollection in Collection object, but I assumed that is for initialized collections already.
Please advice, Thank you