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 ?
Asked
Active
Viewed 226 times
0

Yuvaraj V
- 1,020
- 2
- 16
- 28
-
Why wouldn't you be able to use the `.then` method there? – Explosion Pills Jul 26 '16 at 19:59
-
because .. there is no support for javascript promisses (.then) in node 4.x here you can see .. freature support.. http://node.green/ – Yuvaraj V Jul 27 '16 at 18:18
-
There is no native support for the `Promise` object but if the ArangoJs library implements them on their own you can still use `.then` – Explosion Pills Jul 27 '16 at 18:40
-
No, Now ArangoJS provides native support for promises .. that's why `.then` method 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..) – Yuvaraj V Jul 28 '16 at 04:07
-
I don't think you're understanding. Have you tried to use `.then`? Also, node 4.4 _does_ have native promises – Explosion Pills Jul 28 '16 at 15:57
-
I have already tried `.then` method on node 4.4 .. I know that wouldn't work promises on node 4.4 ... My question is can i still use ArangoJs with node 4.4.. means can i use `node like callbacks ` instead of promises (`.then`) methd.. if so.. please give me an example to create collection in ArangoDb using Arangojs – Yuvaraj V Jul 29 '16 at 04:19
1 Answers
1
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?

dothebart
- 5,972
- 16
- 40
-
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.. – Yuvaraj V Jul 30 '16 at 06:22
-
1@shivaraj try `db.collection('someCollection').create(function (err, res) {...})`? – Alan Plum Aug 01 '16 at 07:37
-
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.. – Yuvaraj V Aug 02 '16 at 12:13