These are chat archives for LearnBoost/mongoose

28th
Jan 2015
Maksim
@chetverikov
Jan 28 2015 03:18 UTC
@vkarpov15 Yes, I don't clearly wrote, sorry +)
I write tests its API. When there are validation errors, mongoose says that there is no handler for error. It turned out that handler there is only one connection, but on the other there. Is there any information how to work with errors in 3.9?
Ismael Gorissen
@igorissen
Jan 28 2015 09:00 UTC

Hello everyone, I have this query

this.find().sort("-count title").skip(offset).limit(limit).exec(callback);

and I want to do a group by or a distinct on title property, how can I achieve this ?
Thanks

Valeri Karpov
@vkarpov15
Jan 28 2015 15:21 UTC

Since you want to skip() and limit(), you need aggregation framework to do this. http://docs.mongodb.org/manual/applications/aggregation/ . Something like

this.aggregate().sort({ count: -1, title: 1 }).skip(offset).limit(limit).group({ _id: '$title' }).exec(callback);

Should work

keep in mind, order of stages matters in aggregation framework, so if you switch the order of sort, skip, limit, and group above you'll get different results