Is it possible to use NodeJs like function Callbacks with ArangoJs 3.x;
I have seen that ArangoJs 3.x using .then method (promises)..
But I am using NodeJs 4.4 .. so i can't use .then method there.. Can I use nodejs like function callbacks for arangojs 3.x ?
1 Answer
Quoting the ArangoJS github page:
// ES2015-style
import arangojs, {Database, aql} from 'arangojs';
let db1 = arangojs(); // convenience short-hand
let db2 = new Database();
let {query, bindVars} = aql`RETURN ${Date.now()}`;
// or plain old Node-style
var arangojs = require('arangojs');
var db1 = arangojs();
var db2 = new arangojs.Database();
var aql = arangojs.aql(['RETURN ', ''], Date.now());
var query = aql.query;
var bindVars = aql.bindVars;
// Using a complex connection string with authentication
let host = process.env.ARANGODB_HOST;
let port = process.env.ARANGODB_PORT;
let database = process.env.ARANGODB_DB;
let username = process.env.ARANGODB_USERNAME;
let password = process.env.ARANGODB_PASSWORD;
let db = arangojs({
url: `http://${username}:${password}@${host}:${port}`,
databaseName: database
});
// Using ArangoDB 2.8 compatibility mode
let db = arangojs({
arangoVersion: 20800
});
Isn't that exactly what you were looking for?
3 Comments
Yuvaraj V
First of all i want to thank for this answer... But this is not exactly what i want.. I have seen it already.. But how can i write same to create a collection.. The same is not working for collections.. if you can please give example to create collection using node js style clalbacks.. because creating collection varies from other stuf..
Alan Plum
@shivaraj try
db.collection('someCollection').create(function (err, res) {...})?Yuvaraj V
Thank you very much @AlanPlum , now i get clear with that.. and please change the answer that only explains our main problem.. give collection example too..
.thenmethod there?Promiseobject but if the ArangoJs library implements them on their own you can still use.then.thenmethod is there.. and working perfectely with node 6.3 .. but my question is .. is , still is it possible to use nodejs like function call backs instead of then.. i asking this for the sake of backword compability to work with older versions of nodejs(where no promise support..).then? Also, node 4.4 does have native promises