neo4j如何取消所有约束 [英] neo4j how to drop all constraints

查看:325
本文介绍了neo4j如何取消所有约束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is there a cypher command to drop all constraints?

我知道我可以放弃特定的约束条件.

I know I can drop specific constraints.

DROP CONSTRAINT ON (book:Book) ASSERT book.isbn IS UNIQUE

但是我想在测试后清除 all 约束作为拆卸的一部分.在文档中找不到任何内容,但类似:

However I want to clear all constraints as part of teardown after testing. Can't find anything in the docs, but something like:

DROP CONSTRAINT *


更新:我的测试设置.


Update: My testing setup.

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

Writing a tiny promise-based nodejs cypher client. I want to test defining unique indexes in application code.

推荐答案

您可以通过对http://localhost:7474/db/data/schema/constraint/http://localhost:7474/db/data/schema/index的GET请求获得所有索引和约束的列表.这是我在Ruby中的操作方法,也许它将为您提供有关如何在Node中执行相同操作的想法.

You can get a list of all indexes and constraints through GET requests to http://localhost:7474/db/data/schema/constraint/ and http://localhost:7474/db/data/schema/index. Here's how I do it in Ruby, maybe it'll give you an idea of how to do the same in 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

这篇关于neo4j如何取消所有约束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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