{"action":"opened","issue":{"url":"https://api.github.com/repos/Automattic/mongoose/issues/6105","repository_url":"https://api.github.com/repos/Automattic/mongoose","labels_url":"https://api.github.com/repos/Automattic/mongoose/issues/6105/labels{/name}","comments_url":"https://api.github.com/repos/Automattic/mongoose/issues/6105/comments","events_url":"https://api.github.com/repos/Automattic/mongoose/issues/6105/events","html_url":"https://github.com/Automattic/mongoose/issues/6105","id":295217194,"number":6105,"title":"mongoose 5.0.3 \"Aggregate has empty pipeline\"","user":{"login":"tferullo","id":8031453,"avatar_url":"https://avatars1.githubusercontent.com/u/8031453?v=4","gravatar_id":"","url":"https://api.github.com/users/tferullo","html_url":"https://github.com/tferullo","followers_url":"https://api.github.com/users/tferullo/followers","following_url":"https://api.github.com/users/tferullo/following{/other_user}","gists_url":"https://api.github.com/users/tferullo/gists{/gist_id}","starred_url":"https://api.github.com/users/tferullo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tferullo/subscriptions","organizations_url":"https://api.github.com/users/tferullo/orgs","repos_url":"https://api.github.com/users/tferullo/repos","events_url":"https://api.github.com/users/tferullo/events{/privacy}","received_events_url":"https://api.github.com/users/tferullo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-07T17:04:54Z","updated_at":"2018-02-07T17:04:54Z","closed_at":null,"author_association":"NONE","body":"<!-- *Before creating an issue please make sure you are using the latest version of mongoose -->\r\n\r\n**Do you want to request a *feature* or report a *bug*?**\r\nBug\r\n\r\n**What is the current behavior?**\r\nAggregate query not working, was working in 4.11 with same data.\r\n\r\nmongo version 3.6 \r\n\r\n**error:**\r\n\r\n```\r\n0|startAPI |   Error:  Aggregate has empty pipeline\r\n0|startAPI |\r\n0|startAPI |   - aggregate.js:692 utils.promiseOrCallback.cb\r\n0|startAPI |     [3.8.0]/[mongoose]/lib/aggregate.js:692:17\r\n0|startAPI |\r\n0|startAPI |   - utils.js:222 Promise\r\n0|startAPI |     [3.8.0]/[mongoose]/lib/utils.js:222:5\r\n0|startAPI |\r\n0|startAPI |   - new Promise\r\n0|startAPI |\r\n0|startAPI |   - utils.js:221 Object.promiseOrCallback\r\n0|startAPI |     [3.8.0]/[mongoose]/lib/utils.js:221:10\r\n0|startAPI |\r\n0|startAPI |   - aggregate.js:690 Aggregate.exec\r\n0|startAPI |     [3.8.0]/[mongoose]/lib/aggregate.js:690:16\r\n0|startAPI |\r\n0|startAPI |   - stats.js:30 router.get\r\n0|startAPI |     <omitted>\r\n0|startAPI |\r\n0|startAPI |\r\n0|startAPI |   - next_tick.js:228 process._tickDomainCallback\r\n0|startAPI |     internal/process/next_tick.js:228:7\r\n\r\n0|startAPI | error: uncaughtException: callback.apply is not a function date=Wed Feb 07 2018 16:50:39 GMT+0000 (UTC), pid=25689, uid=1000, gid=1000, cwd=<omitted> execPath=/home/ubuntu/.nvm/versions/node/v9.0.0/bin/node, version=v9.0.0, argv=[/home/ubuntu/.nvm/versions/node/v9.0.0/bin/node, /usr/lib/node_modules/pm2/lib/ProcessContainerFork.js], rss=329207808, heapTotal=264351744, heapUsed=242126328, external=21623291, loadavg=[0.0380859375, 0.08154296875, 0.02734375], uptime=8038223, trace=[], stack=[  TypeError:  callback.apply is not a function ,   ,   - model.js:3928 ,     [3.8.0]/[mongoose]/lib/model.js:3928:16,   ,   - aggregate.js:693 utils.promiseOrCallback.cb,     [3.8.0]/[mongoose]/lib/aggregate.js:693:14,   ,   - utils.js:211 Object.promiseOrCallback,     [3.8.0]/[mongoose]/lib/utils.js:211:14,   ,   - aggregate.js:690 Aggregate.exec,     [3.8.0]/[mongoose]/lib/aggregate.js:690:16,   ,   - model.js:2809 Function.aggregate,     [3.8.0]/[mongoose]/lib/model.js:2809:13,   ,   - stats.js:28 router.get,     <omitted>,   ,   ,   - next_tick.js:228 process._tickDomainCallback,     internal/process/next_tick.js:228:7,   , ]\r\n```\r\n\r\n**route and query:**\r\n\r\n```js\r\nrouter.get('/', async (req, res, next) => {\r\n  try {\r\n    var match = { status: 'active' };\r\n    var group = {\r\n      _id: null,\r\n      patients: { $sum: '$patients' },\r\n      matchedPatients: { $sum: '$matchedPatients' }\r\n    };\r\n    const matches = await Subscriptions.aggregate({ $match: match }, { $group: group })\r\n      .allowDiskUse(true)\r\n      .exec();\r\n    var patients = matches && matches[0] ? matches[0].patients : 0;\r\n    var matchedPatients = matches && matches[0] ? matches[0].matchedPatients : 0;\r\n    var percentMatch = patients && matchedPatients ? Number(matchedPatients / patients * 100).toFixed(0) : 0;\r\n    res.json({\r\n      patients,\r\n      matchedPatients,\r\n      percentMatch\r\n    });\r\n  }\r\n  catch (err) {\r\n    next(10031);\r\n  }\r\n});\r\n```\r\n\r\n\r\n"}}
{"actor":{"display_login":"tferullo"}}