Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete all collections and documents in ArangoDb

Tags:

arangodb

I am trying to put together a unit test setup with Arango. For that I need to be able to reset the test database around every test.

I know we can directly delete a database from the REST API but it is mentioned in the documentation that creation and deletion can "take a while".

Would that be the recommended way to do that kind of setup or is there an AQL statement to do something similar ?

like image 495
Nicolas Joseph Avatar asked Jan 17 '16 18:01

Nicolas Joseph


People also ask

How do I delete a collection in ArangoDB?

You can for example retrieve the list of all collections (excluding system ones) and drop or truncate them. The latter will remove all documents and keep indexes. Alternatively you can use AQL REMOVE statement.

What is _REV in ArangoDB?

Document Revision Every document in ArangoDB has a revision, stored in the system attribute _rev . It is fully managed by the server and read-only for the user. Its value should be treated as opaque, no guarantees regarding its format and properties are given except that it will be different after a document update.

Is ArangoDB an ACID?

Transactions in ArangoDB are atomic, consistent, isolated, and durable (ACID).


2 Answers

After some struggling with similar need I have found this solution:

for (let col of db._collections()) {

    if (!col.properties().isSystem) {
        db._drop(col._name);
    }
}
like image 175
tlama Avatar answered Oct 06 '22 16:10

tlama


You can for example retrieve the list of all collections (excluding system ones) and drop or truncate them. The latter will remove all documents and keep indexes. Alternatively you can use AQL REMOVE statement.

like image 23
yojimbo87 Avatar answered Oct 06 '22 14:10

yojimbo87