0

I am using Mongo as my primary database and Neo4j to store some relations.Hope Neo4j can reduce the query time for complicated searches in my application.I am confused regarding how to maintain relations between the two.

Here my question how can we create relationship between tables from two different databases in this case?

I am working on Python3.6, Django2.1, django-neomodel 0.0.4,and Djongo 1.2.30

Here is my models.py sample:

class Listing(models.Model):
''' Listing Model for mongo database '''
create_time = models.DateTimeField()
category = models.EmbeddedModelField(
    model_container=Category,
)
subcategory = models.EmbeddedModelField(
    model_container=Subcategory,
    model_form_class=SubcategoryForm
)
...


class Listingnode(DjangoNode):
    uid = UniqueIdProperty()
    list_id = StringProperty()
    status = StringProperty()
    created = DateTimeProperty(default=datetime.utcnow)
    price_range = RelationshipTo('PricerangeNodes','PRICE_RANGE')
    tags = RelationshipTo('TagNodes','TAGS')
Milan
  • 434
  • 1
  • 4
  • 9

1 Answers1

1

You could add an auto generated property id to the MongoDB entity as well as to the Neo4j entity, store the id in the to be linked respectively other entity and load the object via an object graph mapping library (neo4j-ogm) by the stored id if necessary.

1. MongoDB part (Java version)

1.1 YourMongoEntity

@Document
public class YourMongoEntity {
  @Id
  private String id;

  @Indexed(unique = true)
  private String furtherIdentifier;

  // For reasons of clarity the default constructor, getter and setter are omitted.  
}

1.2 YourMongoEntityDAO

@Repository
public interface YourMongoEntityDAO extends MongoRepository<YourMongoEntity, String> {
  YourMongoEntity findById(String id);
}

2. Neo4j part (Java version)

2.1 YourNeo4jEntity

@NodeEntity
public class YourNeo4jEntity  {
  @Id
  @GeneratedValue
  private Long id;

  @Index(unique = true)
  private Long furtherIdentifier;

  // For reasons of clarity the default constructor, getter and setter are omitted.  
}

2.2 YourNeo4jEntityDAO

@Repository
public interface YourNeo4jEntityDAO extends Neo4jRepository<YourNeo4jEntity, Long> {
  YourNeo4jEntity findId(Long id);
}
ThirstForKnowledge
  • 1,245
  • 1
  • 10
  • 27