{"action":"created","issue":{"url":"https://api.github.com/repos/ga-wdi-boston/express-group-project/issues/48","labels_url":"https://api.github.com/repos/ga-wdi-boston/express-group-project/issues/48/labels{/name}","comments_url":"https://api.github.com/repos/ga-wdi-boston/express-group-project/issues/48/comments","events_url":"https://api.github.com/repos/ga-wdi-boston/express-group-project/issues/48/events","html_url":"https://github.com/ga-wdi-boston/express-group-project/issues/48","id":120044493,"number":48,"title":"GET request with aggregation","user":{"login":"baz1389","id":13530918,"avatar_url":"https://avatars.githubusercontent.com/u/13530918?v=3","gravatar_id":"","url":"https://api.github.com/users/baz1389","html_url":"https://github.com/baz1389","followers_url":"https://api.github.com/users/baz1389/followers","following_url":"https://api.github.com/users/baz1389/following{/other_user}","gists_url":"https://api.github.com/users/baz1389/gists{/gist_id}","starred_url":"https://api.github.com/users/baz1389/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/baz1389/subscriptions","organizations_url":"https://api.github.com/users/baz1389/orgs","repos_url":"https://api.github.com/users/baz1389/repos","events_url":"https://api.github.com/users/baz1389/events{/privacy}","received_events_url":"https://api.github.com/users/baz1389/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-12-02T21:55:02Z","updated_at":"2015-12-02T22:23:42Z","closed_at":null,"body":"To preface:\r\n\r\n```\r\nvar pollSchema = new mongoose.Schema({\r\n  title: {\r\n    type: String,\r\n    required: true\r\n  },\r\n  options: {\r\n    type: []\r\n  },\r\n  owner_id: {\r\n    type: String,\r\n    required: true\r\n  }\r\n});\r\n```\r\n\r\n```\r\nvar pollAnswerSchema = new mongoose.Schema({\r\n  pollID: {\r\n    type: String,\r\n    required: true\r\n  },\r\n  answer: {\r\n    type: String,\r\n    required: true\r\n  }\r\n});\r\n```\r\n\r\nWe are trying to search a single Poll using the pollID key in the pollAnswer schema and then aggregate the answers that are already in the database. Below is the current code we have been trying out:\r\n\r\n```\r\nvar read = function (req, res, next) {\r\n  console.log(\"pollAnswer read params id is = \", req.params.id);\r\n  pollAnswer.find({\"pollID\": req.body.pollAnswer}).exec()\r\n  .then(function(){\r\n    console.log(\"req query id: \" + req.body.pollAnswer);\r\n    var agg = pollAnswer.aggregate({ $match: {\"pollID\": \"565f0a753cc192af11e897ba\"}}, { $group: { \"_id\": \"$answer\", \"count\": { $sum: 1 } } });\r\n    res.json(agg);\r\n    console.log(\"aggregation is: \" + agg);\r\n  }).catch(function(error){\r\n    next(error);\r\n  }).then(done);\r\n};\r\n```\r\n\r\ncurl http://localhost:3000/pollanswers/565f0a753cc192af11e897ba\r\n```\r\n\r\nserver error:\r\n\r\n```\r\npollAnswer read params id is =  565f0a753cc192af11e897ba\r\nreq query id: undefined\r\naggregation is: [object Object]\r\nGET /pollanswers/565f0a753cc192af11e897ba 200 2.222 ms - 112\r\n```"},"comment":{"url":"https://api.github.com/repos/ga-wdi-boston/express-group-project/issues/comments/161453036","html_url":"https://github.com/ga-wdi-boston/express-group-project/issues/48#issuecomment-161453036","issue_url":"https://api.github.com/repos/ga-wdi-boston/express-group-project/issues/48","id":161453036,"user":{"login":"baz1389","id":13530918,"avatar_url":"https://avatars.githubusercontent.com/u/13530918?v=3","gravatar_id":"","url":"https://api.github.com/users/baz1389","html_url":"https://github.com/baz1389","followers_url":"https://api.github.com/users/baz1389/followers","following_url":"https://api.github.com/users/baz1389/following{/other_user}","gists_url":"https://api.github.com/users/baz1389/gists{/gist_id}","starred_url":"https://api.github.com/users/baz1389/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/baz1389/subscriptions","organizations_url":"https://api.github.com/users/baz1389/orgs","repos_url":"https://api.github.com/users/baz1389/repos","events_url":"https://api.github.com/users/baz1389/events{/privacy}","received_events_url":"https://api.github.com/users/baz1389/received_events","type":"User","site_admin":false},"created_at":"2015-12-02T22:23:42Z","updated_at":"2015-12-02T22:23:42Z","body":"That didn't change anything either."}}