Introduction to NoSQL | Mongo DB
Table of Contents
- Introduction to NoSQL
- MongoDB
- Sample Project: Real-Time Data Storage with MongoDB
- Conclusion and Next Steps
Introduction to NoSQL
A Brief History of NoSQL
The journey of NoSQL databases began over several decades, with origins in hierarchical and file-based databases before becoming what we know today as “NoSQL.”
NoSQL was first coined in 1998 by Carlo Strozzi to name a file-based database he developed. Ironically, this NoSQL database was actually relational but didn’t use SQL as its interface. Later, in 2009, the term resurfaced when Eric Evans used it to describe the new wave of non-relational databases.
Key Milestones in NoSQL History
- 1960s: Databases like MultiValue (PICK) and IBM IMS, used in Apollo missions, marked the beginnings of hierarchical data storage.
- 1970s: Notable developments included Mumps at Mass General Hospital and DBM at AT&T.
- 1980s-90s: The rise of Lotus Notes (a document database), GDBM by GNU, and Mnesia for telecom signaled increased experimentation.
- 2000s: The NoSQL movement accelerated with the creation of systems like Neo4j (graph database), Memcached (caching layer), CouchDB (document store), and Google BigTable, influencing modern non-relational databases.
For a more detailed timeline, see NoSQL’s History.
MongoDB
MongoDB, a document-based database, was launched in 2007 as part of an open-source cloud computing stack and had its first standalone release in 2009. It quickly gained popularity for its JSON-like document structure, which allows for flexible, dynamic schemas, making it perfect for handling unstructured data.
MongoDB is known for:
- High Scalability: Sharding enables MongoDB to scale horizontally across clusters.
- Flexibility: JSON-like BSON format provides flexible schemas that adjust to data evolution.
- Data Storage & Retrieval Efficiency: An efficient system for real-time data storage and retrieval.
Install MongoDB on Mac
To install MongoDB on macOS, we’ll use Homebrew.
Prerequisites
- Xcode Command-Line Tools: Install by running:
- Homebrew: If not installed, refer to the official Homebrew installation guide.
- MongoDB Tap: Ensure MongoDB is included in your Homebrew by running:
Installing MongoDB 4.4 Community Edition
With prerequisites complete, install MongoDB by executing:
If needed, Homebrew will automatically fetch dependencies like mongodb-database-tools
.
For detailed guidance, check the MongoDB Homebrew installation documentation.
Sample Project: Real-Time Data Storage with MongoDB
This sample project demonstrates MongoDB’s flexibility and schema-free architecture by creating a real-time data storage service to handle dynamic data entries (e.g., customer data in a retail application).
Project Structure
- config/dbConfig.js: MongoDB configuration file.
- models/customer.js: Customer data schema.
- routes/customerRoutes.js: API routes for CRUD operations.
- app.js: Application’s entry point.
Step 1: Setup MongoDB Connection
In config/dbConfig.js
, configure the MongoDB connection.
Step 2: Define Data Schema
In models/customer.js
, create a flexible schema for customer data.
Step 3: Create CRUD Operations
In routes/customerRoutes.js
, create routes for basic CRUD operations.
Step 4: Configure the Application
In app.js
, set up the Express app and integrate MongoDB.
Step 5: Testing and Validation
- Start MongoDB:
- Run the Application:
- Testing CRUD Operations:
- Use Postman or curl to test the API endpoints.
- Verify data persistence in MongoDB by running queries in the Mongo shell.
Conclusion and Next Steps
In this blog, we explored NoSQL’s history and MongoDB’s foundational elements, followed by a practical, real-time data storage project demonstrating MongoDB’s strengths. As NoSQL databases continue to evolve, MongoDB remains a popular choice for applications needing high flexibility and scalability.
Stay tuned for future blogs, where we’ll delve deeper into MongoDB’s advanced features, including indexing, aggregation, and sharding.