neo4j how to drop all constraints

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

Note using APOC you can drop all indexes and constraints via CALL apoc.schema.assert({}, {}).

Tags:

Neo4J

Cypher