getNotifications(query, callback) { const sortedNotifications = this.db.find({}).sort({ts: -1}); const queryCallback = (err, docs) => { if (err) { callback(null, err); return; } callback({notifications: docs, count: this.count}); }; if (query.allNotifications) { sortedNotifications.exec(queryCallback); } else if (query.start != null) { sortedNotifications .skip(Number(query.start)) .limit(Number(query.limit) || DEFAULT_QUERY_LIMIT) .exec(queryCallback); } else { sortedNotifications.limit(Number(query.limit) || DEFAULT_QUERY_LIMIT).exec(queryCallback); } }