2017-12-20 18 views
1

私はArangodbとNode.jsで作業しています。私はdbのedgecollectionを使用しようとしています。私はnpmからarangojsをダウンロードし、サンプルコードを試してみました。Arangodb - アサーションエラーedge._keyを取得しているEDGEとの作業

// ## 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); 

ERROR:

assert.js:42 
throw new errors.AssertionError({ 
AssertionError [ERR_ASSERTION]: undefined == '595783' 
+0

あなたは未定義のエッジが 'included_in'コレクションに実際にあると思いますか? – peak

答えて

1

文書、edgeCollection.edge()非同期ように:

collection.edge('included_in/595783'); 

Promise { 
    <pending>, 
    domain: 
    Domain { 
    domain: null, 
    _events: { error: [Function: debugDomainError] }, 
    _eventsCount: 1, 
    _maxListeners: undefined, 
    members: [] } } 
https://github.com/arangodb/arangojs#edgecollectionedge

プロミス、ないエッジを返します

結果が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プロパティはありません。したがってアサーションエラーです。

GitHub issueからクロスポスト)

関連する問題