我正在与arangodb和node.js一起工作。我正在尝试在DB中使用edgecollection。我已经从NPM下载了Arangojs并尝试了示例代码。
// ## Assigning the values
const arangojs = require('arangojs');
const aqlQuery = arangojs.aqlQuery;
const now = Date.now();
// ## Const variables for connecting to ArangoDB database
const host = '192.100.00.000'
const port = '8529'
const username = 'xyz'
const password = 'XYZ'
const path = '/_db/sgcdm_app/_api/'
const database = 'sgcdm_app'
// ## Connection to ArangoDB
db = new arangojs.Database({
url: http://${host}:${port},
databaseName: database
});
db.useBasicAuth(username, password);
// ## Working with EDGES
const collection = db.edgeCollection('included_in');
const edge = collection.edge('included_in/595783');
const assert = require('assert');
// the edge exists
assert.equal(edge._key, '595783');
assert.equal(edge._id, 'included_in/595783');
console.log(db);
错误:
assert.js:42 throw new errors.AssertionError({ AssertionError [ERR_ASSERTION]: undefined == '595783'
如有记录, edgeCollection.edge()
是 asynchronous :https://github.com/arangodb/arangojs#edgecollection
它返回 Promise ,而不是边缘:
collection.edge('included_in/595783');
Promise {
<pending>,
domain:
Domain {
domain: null,
_events: { error: [Function: debugDomainError] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] } }
您必须 await
结果或使用then()
在结果后立即进行结果。
collection.edge('included_in/595783')
.then(res => { console.log("Key: " + res._key } ));
Key: 595783
您的断言是assert.equal(edge._key, '595783');
,并且由于undefined == '595783'
是错误的而失败。edge
实际上是一个没有_key
属性的承诺对象。因此,断言错误。
(GitHub问题的交叉点)