Search code examples
nosqlgraph-databasesarangodbaqldocument-database

How to store locations in ArangoDB?


I am building a web application where I need to store a large number of unique addresses as nodes in ArangoDB.

One approach would be using a hierarchical graph model: a country node connected to county nodes, county nodes connected to cities and cities connected to exact addresses with GeoJSON attributes.

The other option would be having only address nodes which contain city, county and country as attributes.

Which method would be more beneficial? I would be running queries to find locations in a given range or locations in a given city.


Solution

  • Well, let's see what you will need in terms of collections to build your app:

    1. Collection storing the Places you want to use in your app. This would be your main collection and would contain among other things a map location object {longitude: XXX, Latitude YYY}

    2. Because you probably want people to be able to search by city, country, etc.. You need either a collection per Location type (city, country, etc) or a table with all the locations and a "type" flag that indicates the location is city or country, etc....

    3.- You need a table that allows you to start at a country and drill down to a particular set of cities (for example). So, you need a table with a from key and a to key

    By this point you probably have noticed that we have basically built a hierarchy, which in Arango I would build as at least one Places vertex collection, a Locations vertex collection and a locationContains edge collection. This would allow for really fast lookups and is one of the reasons why graph databases were originally created.

    Now note that since Arango is a multi model DB, you can use the graph syntax (I like anonymous graph syntax myself), but you can also use traditional joins whenever needed, which behave very similar to a traditional relational DB.