Side-by-Side Analysis
Era: 1959 - Mainframe Computing
Approach: Imperative & Procedural
Philosophy: "Tell the computer EXACTLY what to do, step by step"
Control: Complete control over every operation
Focus: Business data processing, batch jobs
Era: 1974 - Relational Revolution
Approach: Declarative & Set-Based
Philosophy: "Describe WHAT you want, not HOW to get it"
Control: Database optimizer makes decisions
Focus: Structured data, transactions, consistency
Era: 2009 - Web Scale Era
Approach: Document-Oriented & Flexible
Philosophy: "Developer-friendly, evolving schema"
Control: Balance of power and flexibility
Focus: Rapid development, horizontal scalability
01 EMPLOYEE-RECORD.
05 EMP-ID PIC X(4).
05 EMP-FIRST-NAME PIC X(20).
05 EMP-LAST-NAME PIC X(20).
05 EMP-DEPARTMENT PIC X(15).
05 EMP-SALARY PIC 9(7)V99.
05 EMP-HIRE-DATE PIC X(10).
* Every record = EXACTLY 78 bytes
* Fixed at compile time
* No optional fields
* Change requires recompilation
CREATE TABLE employees (
id VARCHAR(4) PRIMARY KEY,
first_name VARCHAR(20) NOT NULL,
last_name VARCHAR(20) NOT NULL,
department VARCHAR(15) NOT NULL,
salary DECIMAL(9,2) CHECK (salary >= 0),
hire_date DATE NOT NULL
);
-- Constraints enforced
-- Nullable vs NOT NULL
-- Change via ALTER TABLE
{
_id: "E001",
firstName: "John",
lastName: "Smith",
department: "Engineering",
salary: 85000,
hireDate: ISODate("2020-01-15"),
skills: ["Java", "Python"], // Optional!
contact: { // Nested!
email: "[email protected]"
}
}
// Each document can differ
// No fixed schema
// Add fields anytime
| Aspect | COBOL | SQL | MongoDB |
|---|---|---|---|
| Lines of Code | 11 lines | 2 lines | 7 lines |
| Approach | Field-by-field assignment | Single INSERT statement | JSON-like object |
| Error Handling | Manual file status checks | Automatic constraint validation | Schema validation (optional) |
| Flexibility | Fixed structure only | Must match table schema | Can add extra fields |
OPEN INPUT EMPLOYEE-FILE.
MOVE "E001" TO EMP-ID.
READ EMPLOYEE-FILE
KEY IS EMP-ID.
IF WS-SUCCESS
DISPLAY EMP-FIRST-NAME
ELSE IF WS-NOT-FOUND
DISPLAY "Not found"
END-IF.
CLOSE EMPLOYEE-FILE.
Manual file management required
SELECT first_name, last_name
FROM employees
WHERE id = 'E001';
Database handles everything
db.employees.findOne(
{ _id: "E001" }
)
Simple method call
"Find all Engineering employees earning over $80,000"
PERFORM UNTIL WS-EOF
READ EMPLOYEE-FILE NEXT RECORD
AT END SET WS-EOF TO TRUE
NOT AT END
IF EMP-DEPARTMENT = "Engineering"
AND EMP-SALARY > 80000
DISPLAY EMP-ID " - " EMP-FIRST-NAME
END-IF
END-READ
END-PERFORM.
✓ Complete control
✗ Must scan entire file
✗ Manual loop logic
SELECT id, first_name, last_name, salary
FROM employees
WHERE department = 'Engineering'
AND salary > 80000
ORDER BY salary DESC;
✓ Concise syntax
✓ Automatic optimization
✓ Index usage
db.employees.find({
department: "Engineering",
salary: { $gt: 80000 }
}).sort({ salary: -1 })
✓ Rich operators
✓ Chainable methods
✓ Automatic index usage
| Aspect | COBOL | SQL | MongoDB |
|---|---|---|---|
| Sequential Scan | Excellent | Good | Good |
| Indexed Lookup | Very Fast | Very Fast | Very Fast |
| Complex Joins | Manual (multiple files) | Excellent | Limited ($lookup) |
| Aggregation | Manual calculation | Optimized | Good (pipeline) |
| Memory Usage | Minimal | Moderate | Higher |
| Scalability | Vertical only | Vertical (+ sharding) | Horizontal (native) |
Walk to cabinet → Open drawer → Flip through folders → Read documents → Make notes → Close drawer
Total control, but labor-intensive
Tell librarian what you want → Librarian finds optimal way → Librarian brings exactly what you asked for
Efficient, but within library rules
Describe data in natural structure → Assistant handles storage flexibly → Can reorganize on the fly
Flexible and modern, less rigid structure
Ready to dive deeper into real-world patterns and hard truths about these technologies?
Learn about the common mistake of implementing COBOL-style sequential scanning in MongoDB, and how to avoid building a "distributed COBOL mainframe."
VIEW ANTI-PATTERNS →Discover why each technology still matters in 2024, and learn to match the tool to the problem rather than following trends.
READ CONCLUSIONS →