1

As I understand it, the arangoimp function can import an array of documents into a new collection.

As I have the output of complex join in the form of an array of documents that I would like to create as a new collection. Given this, is there a way to execute arangoimp on the array either as part of the query or, say, arangosh?

Otherwise, my options are: 1) Just suck it up and iterate through the array and save the documents; or 2) Dump the array to a file and import using arangoimp...

Maybe I'm missing something obvious here but I have a bit of time this week trying work out an answer. All thoughts or suggestions gratefully received.

Guido
  • 37
  • 1
  • 7
  • is your join on ArangoDB or in a legacy db? In ArangoDB you can for sure directly insert the joined documents into a new collection. – dothebart May 18 '16 at 07:57
  • @Guido: does your input data reside in ArangoDB, or do you want to import it from another DBMS? – CodeManX Jul 25 '16 at 11:40
  • The data I wanted is in a text file that I wanted to load and run a transformation during the import. The file is big enough to be mildly irritating (~1GB) but my work around was to import into a temporary collection, run a query to create the new collection and drop the temporary collection... – Guido Jul 26 '16 at 18:58

1 Answers1

0

as I understand and correct me if I’m wrong, you want to make it automated. First it will execute the complex join and then will store output array in a new collection.

So based on that , you can write code using arangojs driver.

  Database = require('arangojs').Database;
  db = new Database({url:'http://myapp:_password_@myappserver:8529',databaseName:'myapp-db'});
    var collection = db.collection(collectionName);
    db.query(yourQuery).then(cursor=> {
                return cursor.all();
                 }).then(list =>{
                  collection.import(list);
                });

I haven't tested the code. you can find more here Bulk importing documents

Aymen
  • 133
  • 1
  • 11
  • 1
    That worked. I just had some issues connecting to a remote Arangodb server. For the record, this seemed to work: `Database = require('arangojs').Database; db = new Database({url: 'http://myapp:_password_@myapp-server:8529', databaseName: 'myapp-db' });` Where myapp is the username, myapp-server and myapp-db are the server and database-names (The server is running on the default 8529 port...) – Guido Jun 08 '16 at 17:03
  • You are correct. I will modify my answer based on your input. Thanks – Aymen Jun 13 '16 at 04:25