1

Is there a possibility to reset the indices once I deleted the nodes just as if deleted the whole folder manually?

I am deleting the whole database with node.delete() and relation.delete() and just want the indices to start at 1 again and not where I had actually stopped...

Jon Clements
  • 138,671
  • 33
  • 247
  • 280
lisaBZT
  • 93
  • 1
  • 5

2 Answers2

4

I assume you are referring to the node and relationship IDs rather than the indexes?

Quick answer: You cannot explicitly force the counter to reset.

Slightly longer answer: Generally speaking, these IDs should not carry any relevance within your application. There have been a number of discussions about this within the Neo4j mailing list and Stack Overflow as the ID is an internal artifact and should not be used like a primary key. It's purpose is more akin to an in-memory address and if you require unique identifiers, you are better off considering something like a UUID.

Nigel Small
  • 4,475
  • 1
  • 17
  • 15
  • Hmm... well thanks for your answer! I tried finding the nodes via their names as proposed by the neo4j-examples, but using r = db.query("START n=node:node_auto_index(name='3') RETURN n") does not seem to work... - having given one of the nodes the name "3" with db.nodes.create(name="3"). – lisaBZT Mar 28 '13 at 15:12
  • Which Python library are you using? neo4jrestclient? – Nigel Small Mar 28 '13 at 15:22
  • I'm not super-familiar with the embedded bindings but had you committed your transaction following node creation? – Nigel Small Mar 28 '13 at 15:31
  • ehm. i dont think so... but i was able to find the nodes by their IDs before. just that it doesnt work anymore the way i needed it once i delete them (and the ids didnt start from 1 again). so - i dont know whether i even have to do something like commit. – lisaBZT Mar 28 '13 at 15:36
  • The docs recommend putting your operations into a "with" block which should automatically commit on exit... http://docs.neo4j.org/chunked/1.8/python-embedded-reference-core.html#_transactions – Nigel Small Mar 28 '13 at 16:49
  • the with db.transaction you mean? yep, i did that. i think the nodes are in there just how they are supposed to be, for example with... result = db.query("START n=node({id}) RETURN n", id = n_id) for row in result: node = row['n'] print node.getId() print node.getProperty("name") ...i get the correct properties. it's just that i don't seem to find the right query to get the nodes directly via their properties. – lisaBZT Mar 28 '13 at 16:55
  • and yes, i do see that i wouldnt need a cypher-query there and can simply write "print node.getId() print node.getProperty("name")" for every node thats not 0 ;) – lisaBZT Mar 28 '13 at 17:05
0

You can stop your database, delete all the files in the database folder, and start it again.

This way, the ID generation will start back from 1.

This procedure completely wipes your data, so handle with care.

Now you certainly can do this using Python.

see https://stackoverflow.com/a/23310320

Community
  • 1
  • 1
Donatello
  • 3,486
  • 3
  • 32
  • 38