module.exports = function(Model, perPage) {
	perPage = perPage || 20;
	return function(req, res, next) {
		res.locals.query = req.url.slice(req.url.indexOf('?')).slice(1);
		res.locals.perPage = Math.max(0, req.query.limit) || perPage;

		Model.count(_.omit(req.query, 'limit', 'sort', 'page'), function(err, count) {
			res.data.totalCount = count;
			next(err);
		});
	};
};

module.exports = function(Model, perPage) {
	perPage = perPage || 20;
	return function(req, res, next) {
		//res.locals.query = req.url.slice(req.url.indexOf('?')).slice(1);
		res.locals.query = req.query;
		res.locals.perPage = Math.max(0, req.query.limit) || perPage;

		Model.count(_.omit(req.query, 'limit', 'sort', 'page'), function(err, count) {
			res.locals.totalCount = count;
			next(err);
		});
	};
};

Set query object as a local instead of a query string. Save totalCount on res.locals instead of res.data.
Set query object as a local instead of a query string. Save totalCount on res.locals instead of res.data.
