Arangodb - 使用 EDGE 得到断言错误 edge._key 等于

Arangodb - working with EDGE getting assertion error edge._key equal

我正在使用 Arangodb 和 Node.js。我正在尝试在数据库中使用 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() 异步的 https://github.com/arangodb/arangojs#edgecollectionedge

它returns一个承诺,不是一个边缘:

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实际上是一个Promise对象,它没有_key属性。因此断言错误。

(交叉post 来自GitHub issue