我环顾四周,找不到解决此问题的确切方法。我浏览了 Mongoose 文档并试图找到一种方法。我是 MongoDB 的新手,在学习了很多教程之后,我想致力于制作自己的 API。
目的:
GET 请求http://localhost:3000/seasons/19/1
并返回系列详细信息19
和所选剧集1
就像是:
{
"_id": "5b893aff76c12c166c4e75ae",
"season_number": 19,
"name": "Season 19",
"number_of_episodes": 24,
"episode": [
{
"_id": "5b895e56089a9a152c16af1f",
"episode_number": 1,
"name": "19.01",
"length": "1:23:33",
"author": "Aaron Wright",
"release": "2018-01-13T00:00:00.000Z",
"description": "We kick off our 2018 season with the worst of CES and the future of smart toilets before Aaron unravels the controversial “Dear David” saga that has sparked controversy. We then look at state sponsored mind control programs and the hypnotic experiments performed on unwitting Princeton students in the 1960s."
},
}
问题:
我似乎无法弄清楚如何仅使用一个选定的剧集返回上述对象。由于所有数据都在episodes
但如果我手动使用episodes[0]
等我可以返回它。
这是回购文件,所以不要让这篇文章太长: https ://github.com/DannnB/mysterious-universe-api/blob/master/api/controllers/seasons.js
- 线路:
63
- 姓名:
seasons_get_episode_number
谢谢你的帮助!
该数据库- 托管在 MongoDB Atlas 上 - 免费层,因此无法使用$where
,也不想将$where
其用作繁重的命令。
"data": [
{
"_id": "5b893aff76c12c166c4e75ae",
"season_number": 19,
"name": "Season 19",
"number_of_episodes": 24,
"episodes": [
{
"_id": "5b895e56089a9a152c16af1f",
"episode_number": 1,
"name": "19.01",
"length": "1:23:33",
"author": "Aaron Wright",
"release": "2018-01-13T00:00:00.000Z",
"description": "We kick off our 2018 season with the worst of CES and the future of smart toilets before Aaron unravels the controversial “Dear David” saga that has sparked controversy. We then look at state sponsored mind control programs and the hypnotic experiments performed on unwitting Princeton students in the 1960s."
},
{
"_id": "5b895fee089a9a152c16af20",
"episode_number": 2,
"name": "19.02",
"length": "1:22:11",
"author": "Benjamin Grundy",
"release": "2018-01-20T00:00:00.000Z",
"description": "This week we unravel the cosmic serpent to find the origins of life and the link between DNA and Ayahuasca visions. Could the building blocks of all life also be a conscious force that is capable of direct communication with our altered states of mind?"
}
]
},
{
"_id": "5b893b2276c12c166c4e75b0",
"season_number": 20,
"name": "Season 20",
"number_of_episodes": 9
}, *and so on...*
]