我来自MongoDB,现在我想使用ArangoDb来使用ACID Transactions.我只使用NodeJS进行编程. 我遇到的问题是以下,我无法将NPM代码示例带入生活! 有3个NPM软件包,带有NodeJS驱动程序. 这些代码示例都没
我遇到的问题是以下,我无法将NPM代码示例带入生活!
有3个NPM软件包,带有NodeJS驱动程序.
这些代码示例都没有起作用!
然后,当我尝试使用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’中插入了Document,但是如何指定数据库呢?
另外,你能给我一些关于如何在一个字段上使用Unique Index的’ensureIndex’,’update $set来设置字段和findOne,就像在MongoDB中一样的例子吗?
您也可以使用其中一个NPM包编写代码.但我带来的唯一方法是通过HTTP REST Api ..
拜托,谢谢.我喜欢ArangoDb,因为它的开源,提供ACID交易.但主要缺点是缺乏教程,缺乏示例代码……
*我还需要:在Collection中更新一个字段,如果没有EXIST创建它:*
在这里,您可以看到有关如何仅更新特定字段的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);
}
});
还有一个不断开发的
Javascript/Node.js驱动程序可用于ArangoDB(已确认使用2.0).在这个驱动程序的自述文件中有一些示例如何安装和使用它,文档可用于
here.如果这对您不起作用,请将错误报告发送给我们,然后我们将解决问题.
作为更新问题的代码示例(我刚刚使用了您在MongoDB示例中使用的相同对象,tx.txid必须是文档的_id属性.)您可以使用:
var arango = require('arangojs');
var db = arango.Connection('http://127.0.0.1:8529');
mydb = db.use("yourDatabaseName");
mydb.document.patch(tx.txid, {
nice: tx.nice,
confvalidated: true
});
