Thursday, 10 January 2019

Need help with mongo query

Hello. I need to write simple aggregation, but I have some problems. We are using koa framework with monk module. Here is my code:router.get('/config/getTopTeachers', function *(){try{​var t = yield new Promise(function(resolve, reject) {Class.col.aggregate([{$project: { history_count: { $size: { "$ifNull": [ "$History", []]}}}}, {$sort: {"history_count":-1}}], { cursor: {}},function(err, res) {if (!err){resolve(res);}else{reject(err);}});});​this.body = { out: t }​}catch(e){console.log(e);this.body = { status: false }}});​I've tested the same query without cursor in the mongo shell and it is working. When I want to use it like this it gives no response. I would appreciate if anybody can help me, thanks.

Submitted January 10, 2019 at 09:32AM by raindropzyy

No comments:

Post a Comment