The Care Nexus LogoCareNexus Docs

Database Design

MongoDB schema design, collection relationships, and indexing strategy.

Updated June 2026 7 min read

The Care Nexus uses MongoDB Atlas as its primary database with Mongoose as the ODM layer. The schema is designed around the core entities of the healthcare domain: users, clinics, doctors, patients, appointments, and prescriptions.

Core Collections

CollectionPurposeKey Fields
usersAuthentication identity for all rolesemail, password (hashed), role, isVerified, language
doctorsDoctor profile linked to useruserId, clinicId, specialization, schedule, licenseNo
patientsPatient profile linked to useruserId, dob, bloodGroup, allergies[]
clinicsClinic entity and settingsname, address, phone, doctors[], workingHours
appointmentsAll appointment records across the systemdoctorId, patientId, clinicId, dateTime, status
prescriptionsStructured prescriptions with medicinesdoctorId, patientId, diagnosis, medicines[], audioUrl
medicalrecordsPointer from patient to prescriptionpatientId, prescriptionId, familyMemberId
familymembersDependents linked to patient accountspatientId, name, dob, relationship
messagesEncrypted chat messagesconversationId, senderId, content (encrypted)
conversationsChat rooms between doctor-patient pairsparticipants[], unreadCount
notificationsPersistent notification recordsuserId, type, message, read
revenueentriesConsultation fee recordsdoctorId, appointmentId, amount, createdAt
analyticsNightly aggregated clinic statsclinicId, date, totalPatients, totalRevenue

Key Relationships

User → Doctor / Patient

Each User document represents the authentication identity. Doctor and Patient collections extend it via userId reference. This keeps auth data separate from profile data and simplifies role resolution.

Appointment → Prescription

Each appointment has a 1:1 relationship with prescription via appointmentId. Both entities also store doctorId and patientId for efficient queries without joins.

Indexing Strategy

  • Appointments: compound index on (doctorId, dateTime)
  • Appointments: compound index on (patientId, status)
  • Prescriptions: index on patientId
  • Users: unique index on email
  • Messages: compound index on (conversationId, createdAt)

Connection pooling

The Mongoose connection is initialized once at startup with a max pool size of 10 for efficient request handling. This can be tuned for high-traffic deployments.