Combining Neo4J and MongoDB: Consistency

I am experimenting a lot these days, and one of the things I wanted to do was combine the two popular NoSQL databases, namely Neo4j and MongoDB. Just because I feel that they complement each other perfectly. First-class citizens in Neo4j, relationships, are exactly what is missing in MongoDB, while MongoDb allows me not to put large amounts of data in my node properties.

So, I'm trying to combine the two in a Java application using the Java REST Neo4j binding and the Java MongoDB driver. All my domain objects have a unique identifier, which I store in both databases. Other data is stored in MongoDB, and relationships between objects are stored in Neo4J. For example, both databases contain a user ID, MongoDB contains profile information, and Neo4J contains friendships. With the user level data access I wrote, this works exactly the way I want. And it's fast.

BUT ... When I want to create a user, I need to create both a node in Neo4j and a document in MongoDB. Not necessarily a problem, except that Neo4j is transactional and MongoDB is not. If both were transactional, I would just roll back both transactions when one of them failed. But since MongoDB is not transactional, I cannot do this.

How can I guarantee that whenever I create a user, either node and Document are created, or none of them. I do not want to end up with a lot of documents that do not have node matching.

In addition, I not only want my combined interaction with the database to be ACID compatible, I also want it to be thread safe. Both GraphDatabaseService and MongoClient / DB are provided from single-network.

I found something about creating "transactional documents" in MongoDB, but I don't like it. I would like something nice and clean, like neo4j beginTx, tx.success, tx.failure, tx.finish setup. Ideally, I can implement try / catch / finally in the same block.

Should I make the switch to CouchDB, which looks transactional?

Edit: After several studies triggered by the comment, I realized that CouchDB is also not suitable for my specific needs. To clarify, part of the Neo4j is set in stone. The document repository database is not as long as it has a Java library.

+6
source share
3 answers

Pieter-Jan,

if you can use Neo4j 2.0, you can implement a Schema-Index-Provider (which is very simple), which creates your transactions transactionally in MongoDB.

Since Neo4j makes its indexing providers transactional (from the very beginning), we did this with Lucene, and Redis also has one (needs to be updated). But with Neo4j 2.0, it's a lot easier if you want to check out my implementation for MapDB. ( https://github.com/jexp/neo4j-mapdb-index )

+11
source

Although I'm a big fan of both technologies, I think OrientDB might be the best option for you. It is a graph (like Neo4) and a document (like MongoDB) in one and supports ACID transactions. Sounds like the perfect fit for your needs.

+2
source

As stated here https://stackoverflow.com/questions/23465663/what-is-the-best-practice-to-combine-neo4j-and-mongodb?lq=1 , you can look at Structr.

Its backend can be seen as a Document database around Neo4j. It is fully transactional and open source.

0
source

Source: https://habr.com/ru/post/944430/


All Articles