0

我使用Mongo作为我的主数据库和Neo4j来存储一些关系。希望 Neo4j 可以减少我的应用程序中复杂搜索的查询时间。我对如何维护两者之间的关系感到困惑。

这是我的问题,在这种情况下,我们如何在来自两个不同数据库的表之间创建关系

我正在研究Python3.6、Django2.1、django-neomodel 0.0.4 和 Djongo 1.2.30

这是我的 models.py 示例:

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')
4

1 回答 1

1

您可以将自动生成的属性添加id到 MongoDB 实体以及 Neo4j 实体,将其存储在要分别链接的其他实体中,并在必要时id通过存储的对象图映射库 (neo4j-ogm) 加载对象。id

1.MongoDB部分(Java版)

1.1 你的MongoEntity

@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部分(Java版)

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);
}
于 2018-10-19T16:25:07.663 回答