Tell us what’s happening:
Describe your issue in detail here.
Both get-tests pass, yet the result when entering a query is always an empty array (open=true and open=false for example). the get route to show all issues (/api/issues/apitest) works. The error must be somewhere in the mongoose aggregation block in routes/api.js, but I have no clues as to how to find it. Console gives no errors.
Your project link(s)
solution: https://is-track.herokuapp.com
githubLink: GitHub - danmikes/is-track: A boilerplate for a freeCodeCamp project.
app.route('/api/issues/:project')
.get(function (req, res) {
let projectName = req.params.project;
const {
_id,
issue_title,
issue_text,
created_on,
updated_on,
created_by,
assigned_to,
open,
status_text,
} = req.query;
ProjectModel.aggregate([
{ $match: { name: projectName } },
{ $unwind: "$issues" },
!!_id
? { $match: { "issues._id": ObjectId(_id) } }
: { $match: {} },
!!issue_title
? { $match: { "issues.issue_title": issue_title } }
: { $match: {} },
!!issue_text
? { $match: { "issues.issue_text": issue_text } }
: { $match: {} },
!!created_on
? { $match: { "issues.created_on": created_on } }
: { $match: {} },
!!updated_on
? { $match: { "issues.updated_on": updated_on } }
: { $match: {} },
!!created_by
? { $match: { "issues.created_by": created_by } }
: { $match: {} },
!!assigned_to
? { $match: { "issues.assigned_to": assigned_to } }
: { $match: {} },
!!open
? { $match: { "issues.open": open } }
: { $match: {} },
!!status_text
? { $match: { "issues.status_text": status_text } }
: { $match: {} },
]).exec((err, data) => {
if (!data) {
res.json([]);
} else {
let mapData = data.map((item) => item.issues);
res.json(mapData);
}
})
})
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.115 Safari/537.36
Challenge: Issue Tracker
Link to the challenge: