Reputation: 19
Hi I would like to insert random test data into an edge collection called Transaction with the fields _id, Amount and TransferType with random data. I have written the following code below, but it is showing a syntax error.
FOR i IN 1..30000
INSERT {
_id: CONCAT('Transaction/', i),
Amount:RAND(),
Time:Rand(DATE_TIMESTAMP),
i > 1000 || u.Type_of_Transfer == "NEFT" ? u.Type_of_Transfer == "IMPS"
} INTO Transaction OPTIONS { ignoreErrors: true }
Upvotes: 0
Views: 63
Reputation: 2312
Your code has multiple issues:
_key
key and Arango will create one for you, or you specify one as a string to be used. _id
as a key will be ignored.RAND()
produces a random number between 0 and 1, so it needs to be multiplied in order to make it into the range you want you might need to round it, if you need integer values.DATE_TIMESTAMP
is a function and you have given it as a parameter to the RAND() function which needs no parameter. But because it generates a numerical timestamp (milliseconds since 1970-01-01 00:00 UTC), actually it's not needed. The only thing you need is the random number generation shifted to a range that makes sense (ie: not in the 1970s)i > 1000 ...
line is something I could only guess what it wanted to be. Here the key for the JSON object is missing. You are referencing a u
variable that is not defined anywhere. I see the first two parts of a ternary operator expression (cond ? true_value : false_value
) but the :
is missing. My best guess is that you wanted to create a Type_of_transfer
key with value of "NEFT" when i>1000
and "IMPS" when i<=1000
So, I rewrote your AQL and tested it
FOR i IN 1..30000
INSERT {
_key: TO_STRING(i),
Amount: RAND()*1000,
Time: ROUND(RAND()*100000000+1603031645000),
Type_of_Transfer: i > 1000 ? "NEFT" : "IMPS"
} INTO Transaction OPTIONS { ignoreErrors: true }
Upvotes: 1