Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arangodb 对象数组数据类型_Arangodb_Foxx - Fatal编程技术网

Arangodb 对象数组数据类型

Arangodb 对象数组数据类型,arangodb,foxx,Arangodb,Foxx,这个AQL返回一个我想使用的对象 const keys = db._query(aql` FOR huis IN test FILTER huis._key in ${req.queryParams.keys} RETURN { 'key': huis._key, 'adres': huis.adres, 'postcode': huis.postcode, 'plaats': huis.plaats

这个AQL返回一个我想使用的对象

const keys = db._query(aql`
    FOR huis IN test
    FILTER huis._key in ${req.queryParams.keys}
    RETURN {
        'key': huis._key,
        'adres': huis.adres,
        'postcode': huis.postcode,
        'plaats': huis.plaats
    }
`);
这将返回此对象:

[
  {
    "key": "374875",
    "adres": "Klaverstraat 7",
    "postcode": "2197GV",
    "plaats": "Leiden"
  }
]
那么我想这样拿钥匙:

keys[0].key
当我做小提琴时,这在JavaScript中有效,但在Foxx中无效

const test = [
  {
    "key": "374875",
    "adres": "Klaverstraat 7",
    "postcode": "2197GV",
    "plaats": "Leiden"
  }
]

console.log(test[0].key)
374875

为什么在Foxx中返回“未定义”,但在Fiddle中返回正确的数据?

此Foxx代码:

router.get('/', function (req, res) {
  const test = [
    {
      "key": "374875",
      "adres": "Klaverstraat 7",
      "postcode": "2197GV",
      "plaats": "Leiden"
    }
  ];

  console.log(test[0].key);
  res.status(200).send(test[0]);
}, 'test1')
  .summary('test1')
  .description('test1');
通过REST返回:

{
  "key": "374875",
  "adres": "Klaverstraat 7",
  "postcode": "2197GV",
  "plaats": "Leiden"
}
登录到ArangoDB日志:

374875

当您通过查询获取数据时,需要确保在读取结果内容之前完成查询

请看以下代码:

router.get('/', function (req, res) {
  const keys = db._query(aql`
    FOR huis IN test
    FILTER huis._key == "374875"
    RETURN {
        'key': huis._key,
        'adres': huis.adres,
        'postcode': huis.postcode,
        'plaats': huis.plaats
    }
`).toArray();

  console.log(keys[0].key);

  res.status(200).send(keys);

}, 'test1')
  .summary('test1')
  .description('test1');

此处,
过滤器
条件已更改,并且在执行查询后添加了
.toArray()
。这将确保查询完成,然后
键的内容符合预期。

强制查询返回带有
toArray()的数组。
有效。