Search code examples
arangodbfoxx

Can't switch to database other than _system within Foxx


I'm trying to dynamically generate databases/collections on application startup, in case they do not exist yet. This works fine when working with the _system database. The thing is that it seems not to be allowed when trying to switch to other databases. From the docs:

db._useDatabase(name)

Changes the current database to the database specified by name. Note that the database specified by name must already exist.

Changing the database might be disallowed in some contexts, for example server-side actions (including Foxx).

Does this mean that Foxx applications can only create collections within the _system database? My manifest file sets the isSystem property to false. What is the meaning of such limitation?


Solution

  • A Foxx is included in one database context and has access to the collections there. You can install Foxx apps in different databases. f.E. you can run the following commands in arangosh to install the foxx app "example" in the database "myDB":

    db._useDatabase("myDB")
    fm.install("example","/example")
    

    your app will than be reachable at (assuming standard configuration):

    http://localhost:8529/_db/myDB/example
    

    It is intentionally not possible to access a different database from within a Foxx app.