Overview
Churches are the central organizational unit in the Church Management System. Each church has a pastor (administrator), members, contact information, and associated donation campaigns.Church Schema
The church data model contains all essential information about a church organization:See the complete schema in
churchmodel.js:3-43Church Hierarchy
Pastor (Administrator)
Each church has exactly one pastor who serves as the primary administrator:- Referenced by ObjectId - Links to a User document with
role: "pastor" - Full administrative control - Can manage all church settings and members
- Cannot be removed - The pastor relationship is permanent for the church entity
The pastor field is required during church creation and must reference a user with the pastor role.
Members
Churches maintain an array of member references:- Array of ObjectIds - Each references a User document
- Flexible membership - Members can be added or removed by the pastor
- Cross-referenced - Members can belong to multiple churches if needed
Church Properties
Basic Information
Church Name
Church Name
- Required: Yes
- Unique: Must be unique across all churches
- Type: String
- Used for identification and display throughout the system
Church Address
Church Address
- Required: Yes
- Type: String
- Physical location of the church
- Used for member information and mapping features
Support Contact Information
Thesupportcontact object contains multiple contact methods:
Email Validation
Support contact emails must match the pattern:- Valid email structure
- Proper domain format
- Automatic lowercase conversion
Virtual Fields
Active Members Count
The church schema includes a virtual field that calculates the total number of members:See implementation in
churchmodel.js:45-47Virtual fields are computed at runtime and are not stored in the database. They provide convenient access to derived data without additional storage overhead.
Timestamps
All church documents automatically include timestamp fields:createdAt- When the church was first createdupdatedAt- Last modification timestamp
{ timestamps: true } option.
Relationships
Church → User (Pastor)
- One-to-one relationship
- Required reference
- Pastor must have
role: "pastor"
Church → Users (Members)
- One-to-many relationship
- Array of references
- Members can be added/removed dynamically
Church → Donations
- One-to-many relationship
- Donations reference their parent church
- See Donations for details
Common Operations
Creating a Church
Only users with the
pastor role can create churches.- Pastor ID (must be a valid User ObjectId with pastor role)
- Unique church name
- Physical address
- Support contact (phone and email)
Managing Members
Pastors can add or remove members from their church: Adding a member:- Push the user’s ObjectId to the
membersarray - User must exist in the system
- No duplicate checking is enforced at schema level
- Remove the user’s ObjectId from the
membersarray - Does not delete the user account
- User retains access to their profile
Updating Church Information
All church fields exceptpastor can be updated:
Validation Rules
| Field | Validation |
|---|---|
pastor | Required, must be valid ObjectId |
name | Required, must be unique |
address | Required |
supportcontact.phone | Required |
supportcontact.email | Required, must match email pattern |
supportcontact.website | Optional |
members | Optional array of valid ObjectIds |
Best Practices
- Verify pastor role - Always ensure the pastor field references a user with
role: "pastor" - Validate member IDs - Check that member ObjectIds exist before adding them
- Use activeMembersCount - Leverage the virtual field instead of calculating manually
- Maintain unique names - Church names should be descriptive and unique
- Keep contact info current - Regularly update support contact information