Express + Mongoose 格式化响应发送

Express + Mongoose formatting response to send

我是 javascript 的新手,不确定如何准确地按照我想要的方式设置回复格式。

这是我的 api 的代码:

router.get("/categories", (req, res, next) => {
    try {
        Category.find()
        .then(documents => {
            res.status(200).json({
                documents
            })
        });
    } catch (e) {
        console.log(e)
    }
})

我想将回复发送为:

[
   {data},
   {data},
   {data}   
]

但它是这样发送的:

{
   documents: [
      {data},
      {data},
      {data}
   ]
}

如何删除响应对象中的外层?

干脆不创建带有文档键的对象而是直接向下传递

router.get("/categories", (req, res, next) => {
    try {
        Category.find()
        .then(documents => {
            res.status(200).json(documents)
        });
    } catch (e) {
        console.log(e)
    }
})