Hi,
It's possible to send a JavaScript snippet to the server for execution there.
For
example, the following code can be executed in the arangosh to send the contents of a script file the server and return the script's return value:
arangosh> arango.POST("/_admin/execute?returnAsJSON=true", require("fs").read("test.js"));
An example content for the "test.js" script could be:
return (function () {
var db = require("org/arangodb").db;
db._drop("test");
db._create("test");
for (var i = 0; i < 100; ++i) {
db.test.insert({value:i});
}
return db.test.toArray();
})();
Note
that the code in the script will be executed server-side, and some
variables predefined in arangosh such as "db" and "print" will not be
available there.
If required, these variables need to be initialized in the script as is done with "db" in the example above.
I hope this helps.
Best regards
Jan