Description
Developers using urBackend currently have no way to download or backup their project's data. If they want to migrate, analyze their data locally, or create a snapshot, they are stuck. We need an asynchronous pipeline to export collection data to JSON or CSV formats.
Since collections can grow large, doing this synchronously via an HTTP request will cause timeouts and memory crashes. We need a background job system using BullMQ and Mongoose Streams to handle this safely.
Goals
- Add a new endpoint
POST /api/projects/:projectId/export in the dashboard API to trigger the export job.
- Implement a background worker using BullMQ that connects to the project's MongoDB instance.
- Safely stream the data out using
Model.find().cursor() to avoid running out of memory.
- Convert the stream to JSON/CSV and upload it to the project's Supabase Storage bucket.
- Send an email to the project owner (using the existing Mail API/emailService) with a secure, temporary download link once the export is complete.
Implementation Steps
- Queue Setup: Create a new
dataExportQueue and worker in packages/common/src/queues.
- Dashboard API: Create the trigger endpoint in
apps/dashboard-api and ensure only the project owner can trigger it.
- Worker Logic:
- Use
cursor() on the Mongoose model to stream documents.
- Transform and pipe the data to a temporary file or directly to the Storage bucket (using
apps/public-api/src/controllers/storage.controller.js logic as a reference).
- Generate a presigned download URL.
- Email Notification: Dispatch an email to the user with the download link upon job success, or a failure notification if it errors out.
Skills Required
- Node.js & Express
- Mongoose (Streams and Cursors)
- BullMQ (Background Jobs)
- Supabase Storage
Acceptance Criteria
Description
Developers using
urBackendcurrently have no way to download or backup their project's data. If they want to migrate, analyze their data locally, or create a snapshot, they are stuck. We need an asynchronous pipeline to export collection data to JSON or CSV formats.Since collections can grow large, doing this synchronously via an HTTP request will cause timeouts and memory crashes. We need a background job system using BullMQ and Mongoose Streams to handle this safely.
Goals
POST /api/projects/:projectId/exportin the dashboard API to trigger the export job.Model.find().cursor()to avoid running out of memory.Implementation Steps
dataExportQueueand worker inpackages/common/src/queues.apps/dashboard-apiand ensure only the project owner can trigger it.cursor()on the Mongoose model to stream documents.apps/public-api/src/controllers/storage.controller.jslogic as a reference).Skills Required
Acceptance Criteria