在neo4j中对多个属性创建约束 [英] Creating constraint on multiple properties in neo4j

查看:721
本文介绍了在neo4j中对多个属性创建约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Neo4j的新手,我需要一些帮助.

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. 我需要指定许多属性作为约束,而无需使用命令在所有属性上一次又一次地输入
  2. 我需要将许多属性定义为一"性约束,例如在SQL中,当3个属性是主键且不可分离时.
  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.

我该如何实现?

推荐答案

您实际上是在问两个问题.

You are actually asking 2 questions.

  1. APOC过程 apoc.schema.assert 有助于方便地确保数据库具有所需的索引和约束集. (不过请注意,此过程将删除调用中未指定的所有现有索引和约束.)

  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']});

将返回这样的结果(同样,如果已删除索引或约束,则也将返回action值为"DROPPED"的行):

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│
  └────────────┴───────┴──────┴───────┘

  • 由于尚无任何方法可以在节点标签的多个属性上创建索引或约束,因此一种流行的解决方法是使用一个额外的属性,该属性的值是要使用的值的数组.您将必须确保所有值都属于同一类型,并在必要时进行一些转换.不幸的是,这需要冗余存储一些数据,并使您的代码更加复杂.

  • 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.

    这篇关于在neo4j中对多个属性创建约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆