4

I am new to backend service. I have been trying to make a connection to arangodb from node server. I have a created a basic query in arangodb. the user auth in arangodb is so complicated and there are very few tutorials for node and arangadb combo. I have posted my code below. I have found this example online.

DataService.js

var arangojs = require('arangojs');

// Const variables for connecting to ArangoDB database

const host = '192.100.00.000'
const port = '8529'
const username = 'abcde'
const password = 'abcde'
const path = '/_db/_system/_api/'
const databasename = 'xyzm_app'

// Connection to ArangoDB
var db = new arangojs.Database({
url: `http://${host}:${port}${path}${databasename}`,
databaseName: databasename
});

 db.useBasicAuth(username, password);
//console.log(db);

module.exports = {
getAllControllers : function(){
     return db.query('For x IN {user_details} RETURN NEW {
id: x._user_details/7977010,
name: x.char_ctrl_username,
email:x.char_ctrl_email
}')
    .then(cursor => {
        return cursor.all()

 });
}

query in db

enter image description here

6
  • I don't see any obvious mistakes. Is something not working? Do you get an Error? Please update your post with more details Commented Dec 13, 2017 at 13:59
  • @Lukilas hallo..,there is no connection established. I have been tracking the ip with wireshark and there isno flow at all Commented Dec 13, 2017 at 14:03
  • do you have access to the web interface? should be 192.100.0.0:8529/_db/_system/_admin/aardvark/index.html Commented Dec 13, 2017 at 14:11
  • I think you don't need the path part, since arangojs automatically appends the correct path if you specify the database name. Try this: var db = new arangojs.Database({ url: http://${username}:${password}@${host}:${port}, databaseName: databasename}); Commented Dec 13, 2017 at 14:16
  • @Lukilas yes, i have the access to it. Commented Dec 13, 2017 at 14:20

1 Answer 1

4

From the arangojs README:

// Or using a fully qualified URL containing the database path
const db = new Database({
  url: `http://${username}:${password}@${host}:${port}/_db/${database}`,
  databaseName: false // don't automatically append database path to URL
});
  • databaseName: string (Default: _system)

    Name of the active database.

    If this option is explicitly set to false, the url is expected to contain the database path and the useDatabase method can not be used to switch databases.

So you either specify the full path like http://host:port/_db/dbname and set databaseName: false, or you use http://host:port and either specify databaseName: "dbname" or useDatabase("dbname").

/_api should not be part of the path, ever. arangojs knows where to find the API endpoint and does it for you.

var arangojs = require('arangojs');

// Const variables for connecting to ArangoDB database
const host = '127.0.0.1'
const port = '8529'
const username = 'xyz'
const password = 'xyz'
const databasename = 'sgcdm_app'

 // Connection to ArangoDB
db = new arangojs.Database({
    url: `http://${host}:${port}`,
    databaseName: databasename
});
db.useBasicAuth(username, password);

db.listCollections().then(function(res) {
    res.forEach((coll, i) => {
        console.log(`${i+1}. ${coll.name} (ID=${coll.id}, system=${coll.isSystem})`)
    });
}, function(err) {
    const res = err.response.body;
    console.log(`Error ${res.errorNum}: ${res.errorMessage} (HTTP ${res.code})`);
});

On success (database exists):

1. first (ID=264349479, system=false)
2. test (ID=264349463, system=false)

On error (unknown database):

Error 1228: database not found (HTTP 404)

cross-post from GitHub

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.