node.js - Node/Express Route 'Show' presenting too many results
问题描述
This is for the backend of a MEAN site.
I am currently trying to create several search functions based off of different params in the same mongoose model. For the Controller I have
show:(req,res) => {
Activity.findById
({_id: req.params._id}).then(activity => {
res.json(activity)
})
.then(console.log(req.query._id))
},
show: async (req, res, next) => {
const linkClicked = await Activity.find
({linkClicked: req.params.linkClicked})
.then(result => {
res.send(result)
})
.then(next())
.catch(err => (console.log(err)))
},
show:(req,res, next) => {
Activity.find({caseAssigned: req.params.caseAssigned}).then(action => {
res.json(action)
next()
})
.catch(err => (console.log(err)))
},
show:(req,res, next) => {
Activity.find({addedToQue: req.params.addedToQue}).then(activity => {
res.json(activity)
next()
})
.catch(err =>(console.log(err)))
},
show:(req, res, next) => {
Activity.find({statusChanged: req.params.statusChanged}).then(activity => {
res.json(activity)
next()
})
.catch(err => (console.log(err)))
},
show:(req,res) => {
Activity.findById
({_id: req.params._id}).then(activity => {
res.json(activity)
})
.then(console.log(req.query._id))
},
show: async (req, res, next) => {
const linkClicked = await Activity.find
({linkClicked: req.params.linkClicked})
.then(result => {
res.send(result)
})
.then(next())
.catch(err => (console.log(err)))
},
show:(req,res, next) => {
Activity.find({caseAssigned: req.params.caseAssigned}).then(action => {
res.json(action)
next()
})
.catch(err => (console.log(err)))
},
show:(req,res, next) => {
Activity.find({addedToQue: req.params.addedToQue}).then(activity => {
res.json(activity)
next()
})
.catch(err =>(console.log(err)))
},
show:(req, res, next) => {
Activity.find({statusChanged: req.params.statusChanged}).then(activity => {
res.json(activity)
next()
})
.catch(err => (console.log(err)))
},
For the routes I have:
const express = require('express');
const controllerRouter = express.Router();
const activityController = require("../controllers/activity")
controllerRouter.get("/", activityController.index)
// controllerRouter.get("/search/:_id", activityController.show)
controllerRouter.get("/event/:linkClicked/linkClicked/", activityController.show)
controllerRouter.get("/event/caseAssigned/:caseAssigned", activityController.show)
controllerRouter.get("/event/addedToQue/:addedToQue", activityController.show)
controllerRouter.get("/event/statusChanged/:statusChanged", activityController.show)
When I search in postman for /event/true/linkClicked I receive JSON that does not have linkClicked:true.
Solutions I have tried: 1) I tried implementing the next() function in my controller and adding async capability. I'm not sure if I implemented this correctly. I've made sure that my JSON data is accurate.
Any help is appreciated. (Also, this is my first post so if I have left out a necessary detail, please, let me know.)
解决方案
推荐阅读
- javascript - 异步函数存储另一个异步函数的数据
- rest - 使用机器人框架和 REST 上传带有 Post 请求的 zip 文件
- c# - 我应该在哪里过滤微服务架构模式中的 MS 级外部服务响应?
- powershell - 如何使用powershell运行cmd命令
- javascript - 使用节点中嵌套对象的字符串文字进行 JSON 解析
- javascript - 如何确定使用 JavaScript 进行电子邮件混淆是否有效?
- python-3.x - TypeError:“PngImageFile”对象不可迭代
- java - 硒 moveToElement() 到硒
- django - 如何在我的序列化程序中创建一个字段以避免“TypeError:无法解压缩不可迭代的地址对象”错误?
- python-3.x - 如何使用 np.column_stack 将具有不同列维度(相同行维度)的 4 个向量压缩到 Python 中的变量中?