简体   繁体   English

Foxx服务阵列处理

[英]Foxx Service Array handling

I have a database with documents and I would like to retrieve some data from it providing an array of keys to a Foxx service. 我有一个包含文档的数据库,我想从中检索一些数据,以提供Foxx服务的一系列键。 It works using a single string but I'm missing something about implementing arrays. 它使用单个字符串工作,但是我缺少有关实现数组的一些东西。

UPDATED 更新

router.get('/keys', function (req, res) {

    const keys = db._query(aql`
        FOR huis IN test
        FILTER huis._key in ${req.queryParams.keys}
        RETURN {
            'adres': huis.adres,
            'postcode': huis.postcode,
            'plaats': huis.plaats
        }
    `);

  res.send(keys);
})
.queryParam('keys', joi.array().required(), 'query to search for')
.response(joi.array()
    .items(
        joi.string().required()
    )
    .required(), 'List of house keys.')
    .summary('List house keys')
    .description('Makes LAT LNG from house keys.');

The joi.array() results in a nice interpretation by Arango on the Services overview page as shown below. joi.array()可以使Arango在“服务”概述页面上做出很好的解释,如下所示。 But I handle it wrong because it returns a 404. 但是我处理错了,因为它返回了404。

在此处输入图片说明

If you're passing an array, you will need to use a queryParam or bodyParam and not a pathParam. 如果要传递数组,则需要使用queryParam或bodyParam而不是pathParam。

I'd recommend change your router path to router.get('/keys', function (req, res) { and then access the value as req.queryParams.keys . 我建议将路由器路径更改为router.get('/keys', function (req, res) { ,然后以req.queryParams.keys访问该值。

When you send the array via a queryParam you have a few options, either as /keys?keys=1234,5678 or as /keys?keys=1234&keys=5678 . 当您通过queryParam发送数组时,您有一些选择,如/keys?keys=1234,5678/keys?keys=1234&keys=5678

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM