【发布时间】:2022-01-10 15:09:13
【问题描述】:
我有这样的原始文章集合:
{
title: "how javascript closure works?",
tag: "JS"
},
{
title: "react hooks exploration",
tag: "React"
},
{
title: "Prototype link in Javascript",
tag: "JS"
},
{
title: "Component lifecircle in React",
tag: "React"
}
get url api: /api/articles with controller getArticlesByTag 返回这个 json 数组:
{
tag: "JS",
articles: [
{
title: "how javascript closure works?",
tag: "JS"
},
{
title: "Prototype link in Javascript",
tag: "JS"
},
]
},
{
tag: "React",
articles: [
{
title: "react hooks exploration",
tag: "React"
},
{
title: "Component lifecircle in React",
tag: "React"
},
]
}
articles 数组应该包含所有带有适当标签的文章。
如何使用 mongoose 和 express 做到这一点?
【问题讨论】: