I am coming from MongoDB, and now I would like to use ArangoDb for use of ACID Transactions. I am using NodeJS only for programming.
The problem I encounter is a following, I can not bring the NPM code example to life!
There are 3 NPM packages with Drivers for NodeJS. None of theses code examples is working!
Then, when I try to use instead the HTTP REST API, they do at least partially work. Here is one HTTP REST API approach to access the ArangoDB.
But, how can I specify in what Database the Document should get inserted into? It always inserts it in the _System-Database. Which I dont want.
Here you see my code..
var restify = require('restify');
// Client
var client = restify.createJsonClient({
url: 'http://192.168.142.139:8529',
version: '~1.0'
});
// Now call this insert function to insert a new Document into the ArangoDB Database
insert (function(e,o){
});
function insert ( callback) {
var data = {
user : 'Harryblabla',
nicenumber : 8675,
nicestring : 'des04950'};
client.post('/_api/document?collection=testcollection1&createCollection=true&waitForSync=true',
data, function (err, req, res, obj) {
if (obj.error==false) {
console.log('ok - saved');
console.log('result '+JSON.stringify(obj));
callback (err, 1);
} else {
console.log('not saved');
callback ('error', null);
}
});
}
It does insert the Document in 'testcollection1' but how can I specify into wich Database?
Also, could you give me examples on how to 'ensureIndex' with Unique Index on a field, 'update $set for setting a field, and findOne, like in MongoDB?
You could also write the code with using one of these NPM packages. But the only approach I brought to life is via HTTP REST Api..
please, thanks. I like that ArangoDb because its open source, offers ACID transactions. But major disadvantage is lack of Tutorials, and lack of example code...
* Also I need: UPDATE of a field in Collection, IF NOT EXIST create it:*
Here you can see a NodeJS + MongoDB example on how to update only a specific field. And if it not exists, it will be created. Thats exactly what I also need to ArangoDB in Nodejs. Can you write me an example? please
// Mongo DB connection already opened.
// this is the function to update or create if not exists
mycollection.update({txid: tx.txid},
{$set: {txid: tx.txid, nice: tx.nice, confvalidated: true}}, {upsert: true}, function(err, records1){
if (records1) {
console.log('insertreceived: Amount '+tx.nice+' C: '+tx.confirmations+ 'INSERT RECEIVED: '+tx.txid);
callback(null, records1);
} else {
//callback('error');
callback('error', null);
}
});