我來自MongoDB,現在我想使用ArangoDb來使用ACID事務。我只使用NodeJS進行編程。ArangoDB + NodeJS =需要以下任務的工作示例代碼
我遇到的問題是以下,我不能將NPM代碼示例帶入生活!
有3個帶有NodeJS驅動程序的NPM軟件包。 這些代碼示例都不起作用!
然後,當我嘗試使用HTTP REST API時,它們至少部分工作。 這是訪問ArangoDB的一種HTTP REST API方法。
但是,如何指定文檔應該插入到哪個數據庫?它總是將它插入到_System-Database中。我不想要。
這裏你可以看到我的代碼..
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);
}
});
}
它插入「testcollection1」的文檔,但我怎麼可以指定到至極的數據庫?
另外,你可以給我舉例說明如何在字段上使用唯一索引來確保'確保索引','更新$設置字段和findOne,就像在MongoDB中一樣?
您也可以使用這些NPM軟件包編寫代碼。但我帶來的唯一方法是通過HTTP REST API ..
拜託,謝謝。我喜歡那個ArangoDb,因爲它的開源,提供ACID交易。但是,主要的缺點是缺乏教程,和缺乏示例代碼...
*此外,我需要:在收集現場的UPDATE,如果不存在,請創建它:*
在這裏你可以看到一個NodeJS + MongoDB有關如何只更新特定字段的示例。如果它不存在,它將被創建。這正是我在Nodejs中對ArangoDB所需要的。你能給我寫一個例子嗎?請
// 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);
}
});
也感謝,我會嘗試上面提到的驅動程序。另外我會研究FOXX。這兩種方法似乎都很有趣。我明確需要ACID交易。那樣我比mongoDB更喜歡arangoDB – europeanguy