Creating constraint on multiple properties in neo4j

余生颓废 提交于 2019-12-11 05:47:00

问题


I'm new in Neo4j an I need some help.

I'm trying to make constraint in multiple properties of nodes at once per two meanings:

  1. I need to specify as constraint many properties without typing again and again all over the properties with the command
  2. I need to define many properties as ONE- UNITY constraint like in SQL when 3 attributes is a primary key and not separably.

How can I achieve it?


回答1:


You are actually asking 2 questions.

  1. The APOC procedure apoc.schema.assert is helpful for conveniently ensuring that the DB has the required set of indexes and constraints. (Be aware, though, that this procedure will drop any existing indexes and constraints not specified in the call.)

    For example, as shown in the documentation, this call:

    CALL apoc.schema.assert(
      {Track:['title','length']},
      {Artist:['name'],Track:['id'],Genre:['name']});
    

    will return a result like this (also, if an index or constraint had been dropped, a row with the action value of "DROPPED" would have been returned as well):

      ╒════════════╤═══════╤══════╤═══════╕
      │label       │key    │unique│action │
      ╞════════════╪═══════╪══════╪═══════╡
      │Track       │title  │false │CREATED│
      ├────────────┼───────┼──────┼───────┤
      │Track       │length │false │CREATED│
      ├────────────┼───────┼──────┼───────┤
      │Artist      │name   │true  │CREATED│
      ├────────────┼───────┼──────┼───────┤
      │Genre       │name   │true  │CREATED│
      ├────────────┼───────┼──────┼───────┤
      │Track       │id     │true  │CREATED│
      └────────────┴───────┴──────┴───────┘
    
  2. Since there is not (yet) any way to create an index or constraint on multiple properties of a node label, one popular workaround is to use an extra property whose value is an array of the values you want to use. You will have to make sure the values are all of the same type, converting some if necessary. Unfortunately, this requires storing some data redundantly, and makes your code a bit more complex.



来源:https://stackoverflow.com/questions/41862488/creating-constraint-on-multiple-properties-in-neo4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!