How to solve Arango query promise error? [duplicate]

偶尔善良 提交于 2019-12-10 23:04:55

问题


I have been trying to get a query result from Arangodb in to my front end service (Angular 4) using soap message. I am able to get a result of the query but printed out in console.log. But how can I get it under this function (Service).

So that I can feed into the soap message:

var soap_msg = '<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:examples:CheckUserNameService">' +
  '<soapenv:Header/>' +
  '<soapenv:Body>' +
  '<urn:CheckUserNameResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' +
  '<status xsi:type="xsd:string">' + (Service) + '</status>' +
  '</urn:CheckUserNameResponse>' +
  '</soapenv:Body>' +
  '</soapenv:Envelope>';

I posted this issue got a response saying to use await or .this(), then I have updated my code but still the error remains.

I have tried to feed in to a random variable with some string like this to check the soap msg.,

var payload = [null,"192.168.72.237"];

it works fine.There is a problem with query

var Service = db.query(aqlQuery `
             LET startVertex = (FOR doc IN spec
             FILTER doc.serial_no == '"123456abcde"'
             LIMIT 2
             RETURN doc
             )[0]

            FOR v IN 1 ANY startVertex belongs_to
            RETURN v.ip`, {
  bindVar1: 'value',
  bindVar2: 'value',
}).then(function(res) {
  console.log("doc" + res._result);
})

The versions are

  • "node": "8.9.4"
  • "arangojs": "^5.8.0",
  • "express": "^4.16.2",
  • "express-generator": "^4.15.5"

I don't have a clue to take it forward from here.


回答1:


To have the promise resolve for you, it's necessary to invoke the .all function of the cursor so that it will return the values.

This site has a good example which is simply:

db.query('FOR doc IN documents RETURN doc')
  .then((cursor) => { return cursor.all() })
  .then((doc) => { console.log(doc) });

The promise returned by the first step is then invoked to extract the records, and the return from the cursor is the documents you're looking for.

e.g.

var Service = db.query(aqlQuery `
             LET startVertex = (FOR doc IN spec
             FILTER doc.serial_no == '"123456abcde"'
             LIMIT 2
             RETURN doc
             )[0]

            FOR v IN 1 ANY startVertex belongs_to
            RETURN v.ip`, {
  bindVar1: 'value',
  bindVar2: 'value',
}).then(function(cursor) { // Add this to return the documents in the promise
     return cursor.all()  
}).then(function(res) {
  console.log("doc" + res._result);
})


来源:https://stackoverflow.com/questions/48966201/how-to-solve-arango-query-promise-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!