Importing data from OrientDB to Neo4j
There are tons of options available when it comes to graph databases, such as FlockDB, AllegroGraph, InfiniteGraph, OrientDB, and so on. It is important to learn how to migrate data from any one of these to Neo4j if you are thinking of migrating to Neo4j.
In this recipe, you will learn how to migrate data from OrientDB to the Neo4j server.
Getting ready
To get started with this recipe, install Neo4j using the steps from the earlier recipes of this chapter.
How to do it...
OrientDB is an open source GraphDB, with a mix of features taken from document databases and object orientation.
Exporting in the JSON format
OrientDB has given us the utility to export data in the JSON format. We can access this utility by typing the following commands in a terminal:
$ ./console.sh orientdb> export database graph.json
The JSON format is as follows:
"records": [{ "@type": "d", "@rid": "#12:476", "@version": 0, "@class": "Whiz", "id": 476, "date": "2011-12-09 00:00:00:000", "text": "Los a went chip, of was returning cover, In the", "@fieldTypes": "date=t" },{ "@type": "d", "@rid": "#12:477", "@version": 0, "@class": "Whiz", "id": 477, "date": "2011-12-09 00:00:00:000", "text": "He in office return He inside electronics for $500,000 Jay", "@fieldTypes": "date=t" }
Now, this data can be parsed using a custom script, which can insert data into Neo4j.
Using Gremlin
Gremlin can be used to export data in the XML format from OrientDB and to import data into Neo4j, as shown here:
gremlin> graph = new OrientGraph("local:<path_of_db> "); gremlin> graph.saveGraphML('graph.xml'); gremlin> graph = new Neo4jGraph('data/graph.db'); gremlin> graph.loadGraphML('graph.xml');
Gremlin can also be used to get all the nodes and relationships from OrientDB, which can be inserted into Neo4j, as follows:
gremlin> graph = new OrientGraph("local: <path_of_db> "); gremlin> graph.V # Get All Vertices gremlin> graph.E # Get All Edges
How it works...
Gremlin is a graph traversal language. Gremlin works over those graph databases/frameworks that implement the Blueprints property graph data model. Fortunately, OrientDB and Neo4j are among them.
See also
To find out more about Gremlin, go to http://www.tinkerpop.com/.