Skip to content

[Bug]: listEvents returns all event records with no pagination or document limit, causing unbounded MongoDB queries #281

Description

@anshul23102

Bug Summary

In backend/services/eventService.js, the listEvents function calls eventCrud.list() with no filter, sort limit, or pagination parameters:

const listEvents = async () => eventCrud.list();

This fetches every event document from MongoDB in a single query. As the event collection grows (past events, recurring events, archived records), this endpoint returns an ever-increasing payload, eventually exhausting available memory and causing response timeouts.

Steps to Reproduce

  1. Insert a large number of event documents (e.g., 5000) into the database.
  2. Call GET /api/events (or the frontend page that triggers this service).
  3. Observe the response time increase linearly with document count.
  4. With enough documents, the endpoint times out or causes an out-of-memory crash.

Expected Behavior

The endpoint should apply a default limit and support pagination. The donation.controller.js in the same project already demonstrates the correct pattern:

const listEvents = async ({ page = 1, limit = 20, filter = {}, sort = { schedule: -1 } } = {}) => {
    return eventCrud.list({ filter, sort, skip: (page - 1) * limit, limit });
};

Actual Behavior

All events are fetched unconditionally. Unlike upcomingEvents which uses a date filter and getCampaigns which paginates, listEvents has no upper bound.

Environment

  • Backend: Node.js / Express / Mongoose
  • File: backend/services/eventService.js, function: listEvents

Additional Context

Expected NSOC points: NSOC'26 level2 (medium complexity - unbounded database query causing performance degradation)

Suggested labels: bug, NSOC'26, level2

Checklist:

  • Searched existing issues - not a duplicate
  • Read CONTRIBUTING.md and project rules
  • No AI/Claude mentions
  • No em dashes or double hyphens
  • Repository verified as NSOC

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

NSOC'26Issues for the NSOC 2026 program

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions