Generate test data

josef_richter
Node Link

Is there some simple way to generate random data when playing with Neo4j browser, please? In other databases I can do something like this:

FOR i IN 1..1000
  INSERT {
    name: CONCAT("test", i),
    value: 100 + FLOOR(RAND() * (150 - 100 + 1))
  } IN myCollection

to generate 1000 nodes. Is there something similar in Cypher, please? Thank you.

1 ACCEPTED SOLUTION

You can do something as follows directly in cypher.

with range(1,5) as indexes
unwind indexes as index
create(n:LABEL {randomValue: rand()})
return n

View solution in original post

4 REPLIES 4

josef_richter
Node Link

Seems like I just found it, adding it here for reference: Generating Graphs - APOC Documentation

You can do something as follows directly in cypher.

with range(1,5) as indexes
unwind indexes as index
create(n:LABEL {randomValue: rand()})
return n

excellent, thank you!

glilienfield
Ninja
Ninja

Your welcome. Other math operations you can use can be found here, such as ceil and floor:

And the reference card is great:
https://neo4j.com/docs/cypher-refcard/current/