当前位置: 动力学知识库 > 问答 > 编程问答 >

neo4j - Vertex property (ID) which is a set of unique values

问题描述:

I need to have vertices be uniquely identified and reached fast by every value in a set of values of one property (i.e. this property possibly have more then one value for one vertex), each value should be unique over all vertices (i.e. intersection of any vertex1.id property value (which is a set of vertex ids) with any other vertex2.id is empty, where vertex1 != vertex2)?

This is VERY powerful feature with far reaching implications and I can't find which graph-db engine have built-in facility providing this.

If there is no such built-in feature then may be there are workarounds to acheive this effects?

网友答案:

neo4j allows you to define a Uniqueness Constraint on a node label/property pair that satisfies most of what you want, except that it defines "uniqueness" to apply to the entire property value, not to individual items inside that value. The latter requirement does not seem to be a widely needed feature, since almost all models only require at most one unique identifier.

That being said, here is an example of what you can do, using neo4j, to get what it seems you want.

  1. Create a uniqueness constraint for a special node label, :Uid.

    CREATE CONSTRAINT ON (uid:Uid)
    ASSERT uid.id IS UNIQUE;
    
  2. For every node that needs identifiers, create a relationship to each of its unique IDs.

    CREATE
      (n)-[:HAS_ID]->(:Uid {id: 123}),
      (n)-[:HAS_ID]->(:Uid {id: 234})
      ...
    
  3. When you need to find a node by any of its Uids:

    MATCH (uid:Uid {id: 123})<-[:HAS_ID]-(n)
    RETURN n;
    
分享给朋友:
您可能感兴趣的文章:
随机阅读: