Configure ArangoDB in strapi

I’ve just started testing out strapi and decided to run it against an existing ArangoDB database.

I ran into a small issue with the automatically generated models.

With the default generated code, you’ll notice that records do get added to the database but an E_UNKNOWN error keeps popping up in the admin and the records list has a blank id.

ArangoDB uses a particular id key column called _key.

To get this to work, you need to edit the settings.json file and specify the right id column.

This worked fine for me.

First, remove the id_ref entry that is auto-generated for you:

"id_ref": {
    "type": "int"
  },

and replace it with this:

"id": {
   "type": "int",
   "primaryKey": true,
   "columnName": "_key"
 },

Reload your strapi server and it should all work well.

Note 1:

For reference, this is my database connection:

{
  "orm": {
    "adapters": {
      "disk": "sails-disk",
      "arangodb" : "sails-arangodb"
    },
    "defaultConnection": "default",
    "connections": {
      "default": {
        "adapter": "disk",
        "filePath": ".tmp/",
        "fileName": "default.db",
        "migrate": "alter"
      },
      "permanent": {
        "adapter": "disk",
        "filePath": "./data/",
        "fileName": "permanent.db",
        "migrate": "alter"
        },
    "arangodb": {
        "adapter": "arangodb",
        "host": "localhost",
        "port": 8529,
        "database": "sails-test",
        "graph": "sails-graph"
    }
    }
  }
}

Note 2:

This works for the current version of strapi – 1.5.4 at the time of this article, which uses the Waterline ORM.

They have plans to replace waterline with sequelize in version 2.0.

I’m not sure the reasoning behind it (Waterline supports more wide type of databases, including mongo and arangodb) but this likely won’t work anymore in version 2.0.

I’ll update this if I find a solution for 2.0

Note 3:

You must explicitly specify a "tableName" in the model definition for automatic migration on the sails-arangodb driver to work.

Leave a Reply

Your email address will not be published. Required fields are marked *