Search code examples
arangodbarangojs

Arangodb import from aql query array


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.


Solution

  • 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