如何解决 Arango 查询承诺错误? [英] How to solve Arango query promise error?

查看:37
本文介绍了如何解决 Arango 查询承诺错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用soap消息从Arangodb获取查询结果到我的前端服务(Angular 4).我能够得到查询的结果,但在 console.log 中打印出来.但是在这个功能(Service)下怎么才能得到.

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>';

我发布了这个问题,收到回复说要使用 await 或 .this(),然后我更新了我的代码,但错误仍然存​​在.

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);
})

版本是

  • 节点":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.

推荐答案

为了让 promise 为你解决,需要调用游标的 .all 函数,以便它返回值.

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) });

然后调用第一步返回的promise提取记录,游标返回的是你要找的文档.

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.

例如

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);
})

这篇关于如何解决 Arango 查询承诺错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆