neo4j如何放弃所有约束

AJc*_*dez 17 neo4j cypher

是否有一个cypher命令来删除所有约束?

我知道我可以放弃特定的限制.

DROP CONSTRAINT ON (book:Book) ASSERT book.isbn IS UNIQUE
Run Code Online (Sandbox Code Playgroud)

但是我希望在测试后清除所有约束作为拆解的一部分.在文档中找不到任何内容,但是类似于:

DROP CONSTRAINT *
Run Code Online (Sandbox Code Playgroud)

更新:我的测试设置.

编写一个基于promise的小型nodejs密码客户端.我想测试在应用程序代码中定义唯一索引.

Joh*_*ohn 13

注意使用APOC,您可以通过删除所有索引和约束CALL apoc.schema.assert({}, {}).


sub*_*ris 6

您可以通过GET请求来获取所有的索引和约束的列表http://localhost:7474/db/data/schema/constraint/和http://localhost:7474/db/data/schema/index.这是我在Ruby中的表现,也许它会让你知道如何在Node中做同样的事情.

c.after(:all) do
  conn = Faraday.new(url: "http://localhost:7474")
  response = conn.get('/db/data/schema/constraint/')
  constraints = JSON.parse(response.body)
  constraints.each do |constraint|
    Neo4j::Session.query("DROP CONSTRAINT ON (label:`#{constraint['label']}`) ASSERT label.#{constraint['property_keys'].first} IS UNIQUE")
  end 

  response = conn.get('/db/data/schema/index/')
  indexes = JSON.parse(response.body)
  indexes.each do |index|
    Neo4j::Session.query("DROP INDEX ON :`#{index['label']}`(#{index['property_keys'].first})")
  end
end
Run Code Online (Sandbox Code Playgroud)


mea*_*ppl 5

这是我在Python中执行的操作:

    s = connection.get_session()

    # Drop constraints / indices
    for constraint in s.run("CALL db.constraints"):
        s.run("DROP " + constraint[0])
Run Code Online (Sandbox Code Playgroud)

感觉有些棘手,我觉得约束应该是更好的支持。