2

A deployment script creates and configures databases, collections, etc. The script includes code to drop databases before beginning so testing them can proceed normally. After dropping the database and re-adding it:

var graphmodule = require("org/arangodb/general-graph");
var graphList = graphmodule._list();
var dbList = db._listDatabases();

for (var j = 0; j < dbList.length; j++) {
   if (dbList[j] == 'myapp')
       db._dropDatabase('myapp');
}

db._createDatabase('myapp');
db._useDatabase('myapp');

db._create('appcoll'); // Collection already exists error occurs here

The collections that had previously been added to mydb remain in mydb, but they are empty. This isn't exactly a problem for my particular use case since the collections are empty and I had planned to rebuild them anyway, but I'd prefer to have a clean slate for testing and this behavior seems odd.

I've tried closing the shell and restarting the database between the drop and the add, but that didn't resolve the issue.

Is there a way to cleanly remove and re-add a database?

4
  • did the reply answer your question? if yes, can you mark the answer accepted? if not, whats missing?
    – dothebart
    Commented Feb 18, 2016 at 12:19
  • It was using the correct database. The script also checks for and drops a graph. This would seem redundant since the entire database is dropped but when I move that block to before the db._create('appcoll') line the issue is resolved. The appcoll collection is used in the graph. Is there a residual reference to a graph collection that persists after a database is dropped?
    – gph
    Commented Feb 19, 2016 at 14:08
  • If you create a named graph its managementdata is kept in the system collection _graphs. You should drop a graph via the graph management functions. Another thing relating to graphs is the UI which uses browser storage to remember graph settings.
    – dothebart
    Commented Mar 8, 2016 at 12:41
  • That makes sense and is consistent with behavior I'm seeing. If you respond as a solution I'll mark it as accepted.
    – gph
    Commented Mar 17, 2016 at 2:36

2 Answers 2

1

The collections should be dropped when db._dropDatabase() is called. However, if you run db._dropDatabase('mydb'); directly followed by db._createDatabase('mydb'); and then retrieve the list of collections via db._collections(), this will show the collections from the current database (which is likely the _system database if you were able to run the commands)?.

That means you are probably looking at the collections in the _system database all the time unless you change the database via db._useDatabase(name);. Does this explain it?

1
  • I added additional code from my script to show where I'm trying to switch databases. I do see your point though and there may be a more subtle issue. I'll take a closer look and update back here soon.
    – gph
    Commented Jan 27, 2016 at 5:34
0

ArangoDB stores additional information for managed graphs;

Therefore when working with named graphs, you should use the graph management functions to delete graphs to make shure nothing remains in the system:

var graph_module = require("org/arangodb/general-graph");
graph_module._drop("social", true);

The current implementation of the graph viewer in the management interface stores your view preferences (like the the attribute that should become the label of a graph) in your browsers local storage, so thats out of the reach of these functions.

Not the answer you're looking for? Browse other questions tagged or ask your own question.