How to use mongodb along side neo4j to get predictions

I referred this site to convert my existing mongodb data to neo4j with relationships mappings. I used the following query to fetch data from mongo to neo4j db.

CALL apoc.mongodb.get('connectionString','dbName','TableName',{}) yield value CALL apoc.graph.fromDocument(value, {write: false,skipValidation: true,mappings: {`$`: 'sellers{!_id_,SellerName}', `$.SellerBrandStatistics`: 'brandname{!_id,Brand,ProductCount}', `$.SellerCategoryStatistics`: 'sellerCategory{!_id,CatId,ProductCount,Avg30SalesRank,ProductCountWithAmazonOffer}'}}) YIELD graph AS g1
return g1

but the challenge that I am facing while following this method is that I am not able to map relationship among the documents in the db thus I am stuck with the mapping of relationships only within the document which make me impossible to make product recommendations with cypher query. Can anyone please help me to map relationships among the documents in mongodb?

A couple of thoughts which might help:

  1. You'll want to do this two-pass: import documents in both collections or tables first, and then come back a second time to establish relationships between them, because they need to exist before you can relate them.
  2. You won't use apoc.graph.fromDocument probably to do the linking of documents.

Normally mongo references look something like this:

{
  "_id" : ObjectId("5126bbf64aed4daf9e2ab771"),
  // .. application fields
  "creator" : {
                  "$ref" : "creators",
                  "$id" : ObjectId("5126bc054aed4daf9e2ab772"),
                  "$db" : "users"
               }
}

So let's say we have that document, let's call it "doc". We might do something like this:

WITH doc
MATCH (other:Document { collection: doc.creator.`$ref`, `$id`: doc.creator.`$id` })
CREATE (doc)-[:LINKS_TO]->(other)

Basically, what you do is look up the node referring to the other document by using the fields in the MongoDB reference, and create the relationship that way.

Hope this helps

@david.allen thank you for the response, Referring the site I mentioned the topic with the single command I was able to import the document from mongodb to neo4j. As you mentioned to import all the documents seems better solution but the challenge I am facing is to import all the documents from the mongodb to neo4j db. I was planning to use the following code to import document with relationship to neo4j

CALL apoc.mongodb.get('connectionString','dbName','TableName',{}) yield value CALL apoc.graph.fromDocument(value, {write: false,skipValidation: true,mappings: {`$`: 'sellers{!_id_,SellerName}', `$.SellerBrandStatistics`: 'brandname{!_id,Brand,ProductCount}', `$.SellerCategoryStatistics`: 'sellerCategory{!_id,CatId,ProductCount,Avg30SalesRank,ProductCountWithAmazonOffer}'}}) YIELD graph AS g1
return g1

I also tried to make the database in sync using mongo-connector and Neo4j Doc Manager by the following steps

  1. pip install neo4j-doc-manager --pre
  2. set NEO4J_AUTH=user:password(I used set instead of export since I am using windows machine)
  3. mongod --replSet myDevReplSet
  4. rs.initiate()
  5. mongo-connector -m localhost:27017 -t http://localhost:7474/db/data -d neo4j_doc_manager
    Completing these steps I got the following screen

    But the data was not imported and any of the new data inserted to the mongodb was not reflected in the neo4j. Can you please help me to figure out where I did wrong or I missed any steps?

Unfortunately I think you're going to need to backtrack and take another approach. The neo4j-doc-manager was an open source project which is no longer maintained (GitHub - neo4j-contrib/neo4j_doc_manager: Doc manager for Neo4j) and probably this is failing because it is not using anything close to a recent software stack for Neo4j.

As a result, I'd consider either leaning on the APOC approach, or exporting MongoDB data to JSON and then using apoc.import.json