What is mongo2neo4j?
Imports object relations generated by Object Relation Mappers (ORMs) like Mongoose and stored in MongoDB into the graph database management system Neo4j for exploration with the no-code graphical querying tool SemSpect. Further relations between objects can be specified via options.
References
[1] Graph Exploration By All MEANS With mongo2neo4j and SemSpect; Neo4j Developer Blog (6/2024)
What for?
Imagine you just released your latest MEAN-stack app and want to learn how it is used. You could write some MongoDB queries to find out “how many users of the free tier are at all producing some data?”, “which feature is used most by subscribers?”, … But maybe you never find time to write those queries or you do not know exact what to look for. A graphical large-data exploration tool like SemSpect comes in handy, which allows you to discover patterns in your data by simple navigation.
As SemSpect is layered on top of the graph database system Neo4j as graph app, your MongoDB data needs first to be established in Neo4j. This can be easily achieved using the mongo2neo4j tool.
How does it work?
The mongodb2neo4j
script creates a label (class of nodes) in Neo4j for each collection in the given MongoDB and adds nodes in Neo4j for all documents. Cross-references between MongoDB documents using unique ObjectId
identifiers are turned into Neo4j relations, nicely rendered by SemSpect.
Installation
Install Neo4j
The free Neo4j Desktop works well (see Neo4j)
Install SemSpect Plugin
The free SemSpect Graph App for Neo4j works well (see SemSpect)
Install mongo2neo4j
% pip3 install mongo2neo4j
Run the importer
You can run the mongo2neo4j
importer from the shell by providing at least the name of the MongoDB the data should be imported from. If not specified the default neo4j
DB is targeted with the default neo4j
user. It is likely that you will have to add passwords.
% mongo2neo4j \
[--mongo_host mongodb://<mongo_user>:<mongo_password>@<mongo_host>] \
[--neo4j_user=<neo4j_user>] [--neo4j_password=<neo4j_password>] \
<mongo_db>
Further configuration options are listed on calling
% mongo2neo4j -h
See Script Arguments for the full list of available arguments and the example documenting the workflow of mongo2neo4j using randomly generated sample data.
NOTE: if the APOC plugin is installed in the Neo4j DB, the faster and memory-effective apoc.periodic.iterate
method is used to generate nodes and sublabels.