DEV Community

Cover image for Monday Musings about MongoDB
Hope Clarke
Hope Clarke

Posted on

Monday Musings about MongoDB


Introduction

MongoDB’s history, business need, and inception

To understand how MongoDB came to be, you have to understand a little about it's background. Founder Dwight Merriman created the online advertising agency DoubleClick, with Kevin Ryan joining soon after. DoubleClick absolutely exploded, which created an entirely new-scale problem: managing massive amounts of data. Handling this volume required regional databases and significant infrastructure expenses.

In 2003, Eliot Horowitz joined DoubleClick as a new graduate and quickly became essential. Four years later, all three founders started a new company called 10gen to directly address this exact issue: building a database that could scale horizontally without the overhead of traditional relational systems.

Design

How does MongoDB store information?

MongoDB was named for its goal of handling “humongous” amounts of data. Its core engine was written in C++ and first released in February 2009. Early design philosophy emphasized:

  • CRUD operations for efficiency
  • JavaScript and JSON-style documents for flexibility
  • Fewer manipulation methods to increase speed and scalability
  • Experimental approaches to sharding versus replication

You can still see the first commit here from Dwight!
https://github.com/mongodb/mongo/commit/e73188b5512c82290a4070af4afddac20d0b981e

Here is Dwight Merriman giving the closing Keynote at ZendCon 2011, two years after launch:
Closing Keynote with Dwight Merriman

What made MongoDB so different?

MongoDB stores data in collections of JSON-like documents, rather than rows and tables. This allows developers to add or change fields without restructuring the entire database, which makes it well suited for large, evolving, or semi-structured datasets. Because documents don’t require fixed schemas, MongoDB avoids unnecessary memory overhead.

MongoDB also includes a shell that allows developers to manipulate data using JavaScript commands, making it especially approachable for JavaScript developers.

MongoDB supports multiple clients, including Python, Node.js, Java, and PHP, each with corresponding drivers that communicate with the MongoDB server. The server itself includes a query engine (with a parser, read/write engine, query planner, and DML layer) and a storage engine that persists data and can include encryption.

MongoDB server set up

Visit this Excellent Resource!

Because MongoDB is open source, it can be used for both small applications and very large systems. Its support for sharded clusters enables various fault-tolerant configurations, making it an attractive option for scalable architectures.

Comparisons

How is MongoDB different from SQL-type databases?

In SQL databases, data is stored in tables made up of rows and columns. Each row represents a record, and each column represents a field. This structure enforces strict relationships between data and requires schemas to be defined ahead of time.

This fundamental difference leads to several practical distinctions. MongoDB is better suited for documents, JSON objects, and log-style data, where structure may change frequently. SQL databases require more planning and resources when scaling beyond a single server, whereas MongoDB is designed to handle large volumes of reads and writes across distributed systems.

MongoDB vs SQL

Visit this excellent Resource!

MongoDB allows documents within the same collection to have different fields, while schema changes in SQL affect entire tables. MongoDB’s core concepts are limited to documents, collections, and databases, whereas SQL relies on data types, keys, indexes, joins, and normalization.

That said, SQL databases offer strong consistency guarantees by default. MongoDB prioritizes scalability and performance first, achieving consistency over time depending on configuration and usage.

Queries

How do you use MongoDB for data storage and access?

MongoDB allows developers to use JavaScript to manipulate data. You typically write an app.js file, connect to a database URL, and run the application using Node.js (or a similar runtime).

Once connected, MongoDB provides a rich API that includes functions for inserting, updating, deleting, and querying data, along with comparison, logical, and arithmetic operators. It also supports array operations, indexing, data modeling, and ACID transactions, which allow coordinated operations across multiple documents.

For example, we have a simple lookup where we are trying to find all documents and return just the title and author fields:

// Example query with projections:
db.posts.find({}, { title: 1, author: 1 })
// Database/ posts collection/ find /{} all documents, title & author

Enter fullscreen mode Exit fullscreen mode

You can also make your own functions:

Insert initial function:

const insertDocuments = function(db, callback) {
  const collection = db.collection('documents');
  collection.insertMany(
    [{ a: 1 }, { a: 2 }, { a: 3 }],
    function(err, result) {
      assert.equal(err, null);
      assert.equal(3, result.result.n);
      assert.equal(3, result.ops.length);
      console.log("Inserted 3 documents into the collection");
      callback(result);
    }
  );
};
Enter fullscreen mode Exit fullscreen mode

Final Insert Function:

const MongoClient = require('mongodb').MongoClient;
const assert = require('assert');

const url = 'mongodb://localhost:27017';
const dbName = 'myproject';
const client = new MongoClient(url, { useNewUrlParser: true });

client.connect(function(err) {
  assert.equal(null, err);
  console.log("Connected successfully to server");

  const db = client.db(dbName);

  insertDocuments(db, function() {
    client.close();
  });
});
Enter fullscreen mode Exit fullscreen mode

Compatibility

What technologies does MongoDB work well with?

From mongodb.com:

MongoDB drivers provide APIs that allow applications to connect directly to MongoDB. Most programming languages also have frameworks that build on top of these drivers to provide features like security, workflows, and rapid development. For example, Django is based on Python, and Spring Boot uses Java.

MongoDB supports most major programming languages, including Python, TypeScript, Java, and JavaScript, and works across nearly all major runtimes, IDEs, and GUI tools. It is compatible with macOS, Linux, and Windows, making it easy to integrate into existing development environments.

Final Pros / Cons

What should you consider when choosing MongoDB?

When deciding whether MongoDB is the right choice, it’s important to consider your project’s intended scale, data structure, and long-term flexibility. MongoDB excels when your data model is evolving, when you expect rapid growth, or when horizontal scaling is a priority.

However, that flexibility comes with trade-offs. Applications that rely heavily on complex joins, strict relational integrity, or immediate consistency may be better served by a traditional SQL database. MongoDB requires thoughtful data modeling up front to avoid performance issues later, especially at scale.

Ultimately, MongoDB is best suited for projects where speed, scalability, and flexible schemas matter more than rigid structure. Choosing it should be a deliberate architectural decision based on how your data will grow, change, and be accessed over time.

Helpful Resources to help get you started:

Please visit my wonderful sources- they made this so much easier for me to understand!

History & Introduction, General Resources:

Quick Programming Tips MongoDB history guide

This resource in particular was a huge help!
IBM think topics MongoDB

Geeks for Geeks Database Sharding vs Replication

Geeks for Geeks ACID transactions in MongoDB

Wikipedia MongoDB page

Tutorials, Code Examples, & Reference Documentation:

W3 Schools MongoDB tutorials

Mongod Quick Start Guide

MongoDB Get Started

Comparison & Compatibility:

MongoDB vs SQL by Yash Vardhan Gupta

MongoDB Compatibility

Top comments (0)