如何响应参数名称而不是其ID
我是后端的初学者, 我已经学习nodejs
和mongoose
我响应博客文章这样
[
{
title:"post title" ,
category : 1,
content : "lorem epsom ... "
},
...
]
,这是我的控制器代码,
exports.get = async (req, res, next) => {
try {
const posts= await Post.find()
res.send(posts)
} catch (err) { next(err) }
}
但是现在我想要这样回答:
[
{
title:"post title" ,
category : "category A",
content : "lorem epsom ... "
},
...
]
将类别保存到名为类别的另一个表中 那么如何发送类别名称而不是其ID?
I am beginner with backend ,
I've learning nodeJs
and Mongoose
I respond blog posts like this
[
{
title:"post title" ,
category : 1,
content : "lorem epsom ... "
},
...
]
and this is my controller code
exports.get = async (req, res, next) => {
try {
const posts= await Post.find()
res.send(posts)
} catch (err) { next(err) }
}
But now I want to respond like this :
[
{
title:"post title" ,
category : "category A",
content : "lorem epsom ... "
},
...
]
categories are saved into another table named Category
so how can I send category name instead of its Id ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论