ApiaryActive
Try: pause · settings · learn · wipe
← Community / Reading Room
ND
pioneers · 16 min read

NoSQL Databases And Data Storage

The world’s data is exploding faster than any previous generation of technology could have imagined. In 2023, the global data sphere surpassed 97…

Published on Apiary – the hub where bee conservation meets self‑governing AI agents.


Introduction

The world’s data is exploding faster than any previous generation of technology could have imagined. In 2023, the global data sphere surpassed 97 zettabytes—roughly the amount of information that could fill 200 million Blu‑Ray discs. Enterprises, research labs, and citizen‑science projects alike are scrambling to capture, process, and preserve that flood of information before it dissipates into noise. Traditional relational databases, with their rigid schemas and vertical‑scale limits, are increasingly being outpaced by workloads that demand agility, massive concurrency, and geographically distributed storage.

Enter NoSQL—a family of data‑storage technologies built to handle unstructured, semi‑structured, and rapidly evolving data models. Among the many NoSQL offerings, MongoDB has emerged as a de‑facto standard for developers who need a flexible, high‑performance alternative to relational databases. Its document‑oriented approach mirrors the way modern applications think about data: as JSON‑like objects that can nest, evolve, and be indexed for lightning‑fast retrieval. For a platform like Apiary, which must ingest sensor streams from thousands of hives, serve dynamic dashboards to conservationists, and power AI agents that make autonomous decisions about pollinator health, MongoDB’s capabilities are not just convenient—they are essential.

In this pillar article we will explore the technical foundations of NoSQL, dissect MongoDB’s architecture, and illustrate how these tools empower real‑world projects—from global e‑commerce giants to the humble beekeeping community. By the end, you’ll have a roadmap for choosing the right storage strategy, tuning it for performance, and integrating it with AI agents that responsibly steward our planet’s most vital pollinators.


The Evolution of Data Storage: From Relational to NoSQL

When E.F. Codd introduced the relational model in 1970, the promise was clear: data could be stored in tables, queried with a declarative language (SQL), and remain consistent across transactions. For decades, that model powered everything from banking to airline reservations. Yet the model also imposed constraints that grew painful as applications became more data‑intensive:

ChallengeRelational SolutionWhy It Fell Short
Schema rigidityALTER TABLE statementsRequires downtime; schema migrations become complex as data models evolve
Horizontal scalingSharding via manual key designDifficult to implement; often leads to cross‑shard joins that degrade performance
Variable data structuresNormalization with many tablesJoins become costly; developers must map object hierarchies to flat tables manually
High‑velocity writesBulk inserts, batch processingTransaction logs become bottlenecks; latency spikes under load

The rise of the web in the early 2000s, followed by mobile, IoT, and AI workloads, created a new set of requirements: massive write throughput, schema flexibility, and geo‑distributed availability. Companies like Amazon, Google, and Facebook built internal storage engines that sidestepped relational constraints, publishing their lessons as open‑source projects. The term NoSQL—originally coined as “not only SQL”—captured the spirit of these systems: they could still support SQL‑like queries but were not bound by relational rules.

MongoDB entered the scene in 2007 as a document‑store built on top of a BSON (binary JSON) format. Its early adoption by startups was driven by two key promises:

  1. Schema‑on‑read – developers could store heterogeneous documents in the same collection, adding fields as the application grew.
  2. Horizontal scalability – the database could automatically partition data across multiple servers (sharding) without manual key design.

Fast forward to 2024, MongoDB now powers over 35 % of the NoSQL market (according to the DB‑Engines ranking) and boasts 30 billion+ queries per day across sectors ranging from finance to environmental monitoring. For platforms that need to ingest millions of sensor events per hour—such as hive temperature, humidity, and acoustic signatures—MongoDB’s model aligns naturally with the data’s nested, time‑series nature.


Core Principles of NoSQL – The Four Types

NoSQL is not a monolith; it is a taxonomy of storage models, each optimized for a particular access pattern. Understanding the four primary families helps you decide where MongoDB fits and where complementary technologies might be needed.

TypeData ModelTypical Use‑CaseExample
DocumentJSON‑like objects (BSON) stored in collectionsContent management, catalogs, sensor logsMongoDB
Key‑ValueSimple key → value mapping, often in memoryCaching, session storesRedis, DynamoDB (when used as KV)
Column‑FamilyWide rows with dynamic columns, stored in columnar filesTime‑series analytics, large‑scale OLAPApache Cassandra, HBase
GraphNodes and edges with propertiesSocial networks, recommendation enginesNeo4j, Amazon Neptune

MongoDB’s document model is uniquely positioned for heterogeneous data. A hive sensor payload might look like:

{
  "hiveId": "BEE-001",
  "timestamp": "2026-06-22T14:03:21Z",
  "environment": {
    "temperatureC": 34.2,
    "humidityPct": 71,
    "windSpeedKmH": 5.1
  },
  "audio": {
    "spectrogram": "...base64...",
    "peakFrequencyHz": 2500
  },
  "alerts": ["highTemp"]
}

Notice the nested objects (environment, audio) and the optional alerts array—MongoDB can store this document unchanged alongside another that contains a queenStatus field. This flexibility eliminates costly migrations and enables rapid iteration on data‑collection pipelines.


MongoDB’s Document Model – How It Works

BSON: The Binary Backbone

MongoDB stores data as BSON (Binary JSON), a binary-encoded serialization of JSON that adds support for data types not present in plain JSON, such as Date, ObjectId, Decimal128, and Binary. BSON’s design balances human readability (when converted back to JSON) with efficient storage and traversal. For example, a 64‑bit ObjectId encodes a timestamp, machine identifier, process ID, and a counter, allowing MongoDB to generate globally unique identifiers without a central authority.

Collections and Databases

A database is a logical namespace; within it, a collection groups related documents. Collections are schema‑less, meaning each document can have a different set of fields. However, best practice encourages a schema design (documented in a separate schema-design-guidelines page) to ensure predictable query patterns and index usage.

Query Language – The MongoDB Query Language (MQL)

MongoDB’s query language mirrors JavaScript object syntax, making it intuitive for developers familiar with JSON. A typical find operation looks like:

db.hiveReadings.find({
  "environment.temperatureC": { $gt: 30 },
  "timestamp": { $gte: ISODate("2026-06-01") }
}).sort({ timestamp: -1 }).limit(100)

MQL supports aggregation pipelines, allowing complex transformations (group, unwind, project) directly on the server. For time‑series analysis, the $bucketAuto stage can automatically partition readings into temperature ranges, a feature heavily used in Apiary’s heat‑stress dashboards.

Indexing – From B‑Tree to Geospatial

MongoDB automatically creates a primary index on the _id field, but production workloads rely on secondary indexes to achieve sub‑millisecond latency. The engine supports:

Index TypeUse‑CaseExample
B‑TreeExact match, range queries{ "environment.temperatureC": 1 }
CompoundMulti‑field queries, sort optimization{ "hiveId": 1, "timestamp": -1 }
TTL (Time‑To‑Live)Auto‑expire old sensor data{ "timestamp": 1 }, expireAfterSeconds: 2592000
Geospatial (2dsphere)Location‑based queries, e.g., nearest hives{ "location": "2dsphere" }
TextFull‑text search on notes or logs{ "notes": "text" }

In practice, a well‑designed index can reduce a query that scans millions of documents to a handful of index entries, delivering latency under 5 ms even under heavy load.


Performance and Scalability – Real‑World Benchmarks

MongoDB’s promise of high performance is backed by numerous benchmark studies and production anecdotes. Below are three representative scenarios that illustrate its capabilities.

1. High‑Velocity Writes – IoT Sensor Stream

A global beekeeping network deployed 10,000 sensors across 5 continents, each sending a JSON payload (~500 B) every 30 seconds. That translates to ~170 KB/s per sensor, or ~1.7 GB/s aggregate ingest. Using a sharded cluster with 12 replica set members (each node a 32‑core, 256 GB RAM server), MongoDB sustained ~1.2 M writes/second with average write latency of 2.3 ms (as measured by the internal mongostat tool). The cluster leveraged wiredTiger’s compression (zstd) to reduce storage consumption by ~45 % compared to raw JSON.

2. Read‑Heavy Analytics – E‑Commerce Catalog

An online marketplace with 50 M product documents (average size 2 KB) required sub‑10 ms latency for facet searches (price, category, brand). By creating compound indexes on { "category": 1, "price": 1 } and employing covered queries (where the query can be satisfied entirely from the index), the system achieved ~18 k reads/second per node with 99th‑percentile latency < 12 ms. The key was index projection, eliminating the need to fetch full documents.

3. Multi‑Region Replication – Global SaaS

A SaaS platform serving users in North America, Europe, and Asia‑Pacific used MongoDB’s multi‑region replica sets (via Atlas Global Clusters). By placing a primary in the US‑East region and read‑only secondaries in Europe and APAC, latency for read operations dropped from ~120 ms (single‑region) to ~30 ms for users near secondary nodes. The automatic failover time during a simulated primary outage averaged ~6 seconds, meeting the service‑level agreement (SLA) of < 10 seconds for continuity.

These benchmarks confirm that MongoDB can handle high write rates, low‑latency reads, and geo‑distributed workloads—the exact mix needed for modern conservation platforms that must store sensor data, serve dashboards, and provide near‑real‑time insights to AI agents.


Data Modeling Strategies – Embedding vs Referencing

A central design decision in MongoDB is whether to embed related data within a single document or reference it across collections. The choice impacts query complexity, write patterns, and storage efficiency.

Embedding (Denormalization)

When to use: Data that is tightly coupled and frequently accessed together. Example: a hive’s daily temperature readings.

{
  "hiveId": "BEE-001",
  "date": "2026-06-22",
  "readings": [
    { "time": "08:00", "tempC": 32.1 },
    { "time": "12:00", "tempC": 34.5 },
    { "time": "16:00", "tempC": 33.8 }
  ]
}

Pros:

  • Single‑document reads – All needed data retrieved in one operation.
  • Atomic updates – MongoDB can modify the entire document in a single transaction, preserving consistency.
  • Reduced index overhead – Fewer collections mean fewer indexes to maintain.

Cons:

  • Document size limit – MongoDB caps documents at 16 MB; large time‑series may exceed this.
  • Write amplification – Updating a single embedded element rewrites the whole document.

Referencing (Normalization)

When to use: Data that is shared across many documents or grows unbounded, such as a master list of hive locations.

// Hive collection
{
  "_id": ObjectId("..."),
  "hiveId": "BEE-001",
  "locationId": ObjectId("LOC-45")
}

// Locations collection
{
  "_id": ObjectId("LOC-45"),
  "lat": -23.567,
  "lon": 45.123,
  "region": "Cape Town"
}

Pros:

  • Scalability – Large or unbounded data (e.g., daily logs) can be stored in separate collections without hitting size limits.
  • Data reuse – The same location document can be linked to many hives, reducing duplication.

Cons:

  • Additional round‑trips – Queries may need $lookup stages (joins) or multiple reads.
  • Consistency management – Updates to referenced documents must be coordinated, potentially requiring multi‑document transactions.

Hybrid Approach

In practice, many systems adopt a hybrid model: embed recent readings for fast access, while archiving older data in a separate time‑series collection (MongoDB 5.0 introduced native time‑series collections). The platform can then run aggregation pipelines that merge the two sources when constructing long‑term trend reports.


Operational Considerations – Indexing, Sharding, and Replication

Running MongoDB in production demands careful attention to three pillars: indexes, sharding, and replication. Each contributes to performance, availability, and data durability.

Index Management

  • Index selection should be driven by query profiling (db.collection.explain("executionStats")). Unused indexes waste RAM and degrade write throughput.
  • Wildcard indexes ({ "$**": 1 }) can simplify search across heterogeneous fields but increase index size dramatically. Use them only when the schema is truly unpredictable.
  • Partial indexes ({ "alerts": { $exists: true } }) restrict the index to documents that meet a filter, conserving space and speeding writes.

Rule of thumb: Keep the working set (frequently accessed data + indexes) within RAM. For a 64 GB instance, aim for a working set ≤ 48 GB to avoid page faults.

Sharding Strategies

MongoDB shards data horizontally across shard keys. A well‑chosen shard key distributes documents evenly and minimizes chunk migrations. Common patterns:

Shard KeyDistributionTypical Use
hashed ({ _id: "hashed" })Uniform random distributionGeneral purpose when no natural range key exists
range ({ timestamp: 1 })Time‑ordered distributionTime‑series data, logs
compound ({ hiveId: 1, timestamp: -1 })Balanced per‑hive loadMulti‑tenant sensor streams

During peak ingestion, MongoDB automatically splits chunks once they exceed 64 MB, then balances them across shards. Monitoring the balancer process (via db.getSiblingDB("config").settings.find()) ensures that no single shard becomes a hotspot.

Replication and Fault Tolerance

A replica set provides redundancy by maintaining multiple copies of each shard. The primary handles writes; secondaries replicate asynchronously. Key parameters:

  • Write Concern (w: "majority"): Guarantees that a write is persisted to a majority of nodes before returning success. In a 3‑node replica set, this means at least 2 nodes.
  • Read Preference (secondaryPreferred): Allows reads from secondaries, reducing load on the primary and improving read latency for geographically distant clients.
  • Majority Commit Point: Introduced in MongoDB 4.2, it tracks the latest operation that has been committed by a majority of replica set members, providing stronger consistency guarantees.

For mission‑critical data—such as hive health alerts that trigger automated interventions—setting w: "majority" ensures that no alert is lost even during a primary outage.


Security, Compliance, and Governance in NoSQL

Data stewardship is not merely a technical concern; it carries ethical, legal, and ecological responsibilities. MongoDB offers a suite of features that help organizations meet compliance frameworks (GDPR, HIPAA) and maintain transparent data governance.

Authentication and Authorization

  • SCRAM‑SHA‑256 is the default authentication mechanism, providing strong password hashing.
  • Role‑Based Access Control (RBAC) lets you define granular privileges, e.g., a sensor_ingest role that can only insert into the readings collection, while a data_analyst role can find and aggregate across multiple collections.
  • LDAP integration enables centralized user management, useful for research consortia.

Encryption

  • At‑rest encryption (via the WiredTiger storage engine) encrypts data files using the AES‑256‑GCM algorithm. MongoDB Atlas offers encryption‑at‑rest as a managed service.
  • In‑transit TLS protects data moving between clients, shards, and replica set members. Enforcing TLS 1.3 reduces handshake latency while providing forward secrecy.

Auditing and Data Lineage

MongoDB’s audit log records every privileged operation, including query filters and document changes. By exporting audit events to a SIEM (Security Information and Event Management) system, organizations can track who accessed hive health data and when—critical for accountability in citizen‑science projects.

Data Retention Policies

Bee‑conservation data often has a legal retention period (e.g., 5 years for environmental monitoring). MongoDB’s TTL indexes automate expiration: a field createdAt with expireAfterSeconds: 157680000 (5 years) will purge stale documents without manual scripts.

Governance with AI Agents

When integrating self‑governing AI agents (see ai-agent-framework), it is essential to enforce data‑access contracts. By assigning each agent a dedicated service account with a least‑privilege role, you prevent unintended data leakage while allowing agents to read sensor streams and write recommendations back to a decisions collection.


Case Studies – From E‑Commerce to Bee‑Conservation Platforms

1. Global Retailer: Real‑Time Product Recommendations

A multinational retailer migrated 150 TB of product catalog data from MySQL to MongoDB to support real‑time recommendations. By storing each product as a document with nested attributes (price, inventory, tags), they eliminated costly joins. The system now serves ~2 M recommendation queries per second, with average latency of 8 ms. The move also reduced operational costs by 30 % because they could retire several read‑replica MySQL servers.

2. Climate Research: Satellite Imagery Metadata

NASA’s Earth Observing System uses MongoDB to catalog metadata for petabytes of satellite images. Each image document contains geospatial coordinates, acquisition timestamps, and sensor parameters. The platform runs geospatial queries ($geoNear) to retrieve all images intersecting a protected bee habitat. This enables researchers to overlay climate data with hive health metrics, generating actionable insights for policymakers.

3. Apiary’s Hive Sensor Network

Apiary has deployed 12 000 IoT sensors across North America, each sending a JSON payload (≈400 B) every minute. The incoming stream is ingested via an Apache Kafka connector into a MongoDB Atlas cluster with 4 shards (each a 48‑core, 384 GB RAM instance). Highlights:

MetricValue
Peak write throughput1.5 M docs/s
Average write latency2.1 ms
Storage growth2.3 TB per month (compressed)
Query latency for dashboard12 ms (95th percentile)

The platform leverages time‑series collections for temperature and humidity, TTL indexes to purge raw audio after 30 days, and compound indexes on { hiveId: 1, timestamp: -1 } for rapid retrieval of the latest readings. AI agents, built on the ai-agent-framework, consume the latest data to trigger automated alerts when temperature exceeds 35 °C for more than 3 hours, prompting beekeepers to deploy cooling measures.


Integrating AI Agents with NoSQL – Patterns and Pitfalls

Self‑governing AI agents require low‑latency data access, transactional guarantees, and clear audit trails. MongoDB’s design offers several integration patterns:

1. Event‑Driven Architecture

Agents subscribe to a change stream (db.collection.watch()) that emits real‑time events whenever a document is inserted, updated, or deleted. This enables a reactive loop: sensor data arrives → change stream fires → AI agent evaluates → decision written back. Change streams are ordered and resume-able, guaranteeing that agents never miss an event even after a restart.

2. Transactional Workflows

When an agent must update multiple collections atomically (e.g., write a decision document and update a hiveStatus flag), MongoDB’s multi‑document ACID transactions (available since 4.0) provide the needed consistency. Example:

const session = client.startSession();
session.startTransaction({ readConcern: { level: "majority" }, writeConcern: { w: "majority" } });
try {
  db.decisions.insertOne({ hiveId, action: "activateCooler", timestamp: new Date() }, { session });
  db.hives.updateOne({ hiveId }, { $set: { coolingActive: true } }, { session });
  await session.commitTransaction();
} finally {
  await session.endSession();
}

3. Model Storage and Feature Retrieval

Machine‑learning models (e.g., a TensorFlow model predicting colony collapse) can be stored as binary blobs in MongoDB using the GridFS specification, which splits large files into chunks. Agents can retrieve the latest model version with a query on modelVersion and load it directly into memory, ensuring that inference runs against the most recent data.

Pitfalls to Avoid

PitfallSymptomRemedy
Unbounded growth of change streamsOOM errors on agentsUse resume tokens and set appropriate maxAwaitTimeMS to throttle consumption
Heavy write amplification from embedded arraysWrite latency spikes > 50 msSwitch to time‑series collections or break out large arrays into separate documents
Inconsistent read preferencesStale data leading to wrong decisionsEnforce readConcern: "majority" for critical reads, or use causal consistency with afterClusterTime
Insufficient index coverageFull collection scans during alertsAdd compound indexes that match the exact query pattern used by agents

By adhering to these patterns, AI agents can act autonomously yet responsibly, aligning with Apiary’s mission to empower both humans and machines in the service of pollinator health.


Future Trends – Multi‑Model, Serverless, and Edge Storage

The NoSQL landscape continues to evolve, and MongoDB is positioning itself at the forefront of several emerging trends.

Multi‑Model Capabilities

MongoDB 6.0 introduced native support for graph traversal using the $graphLookup aggregation stage, allowing developers to model hive relationships (e.g., neighbor colonies, foraging routes) without a separate graph database. This multi‑model approach reduces data duplication and simplifies the tech stack.

Serverless and Fully Managed Deployments

MongoDB Atlas now offers Serverless Instances, where capacity scales automatically based on workload. For sporadic data bursts—such as a sudden swarm of acoustic recordings during a heatwave—serverless can handle spikes without pre‑provisioning, charging only for actual usage. This aligns with sustainability goals by minimizing idle compute.

Edge Storage and Sync

IoT devices in remote apiaries often operate with intermittent connectivity. MongoDB’s Realm Sync (formerly Stitch) enables offline-first applications: devices write to a local Realm database, which syncs to the cloud when network access returns. This pattern ensures that critical sensor data is never lost, while also reducing bandwidth consumption.

Quantum‑Ready Encryption

Although still experimental, MongoDB’s roadmap includes post‑quantum cryptography for data‑at‑rest encryption, preparing the platform for a future where classical encryption could be vulnerable. Early adopters in the scientific community are already testing NIST‑approved lattice‑based algorithms within MongoDB’s encryption framework.

These trends suggest that NoSQL, and MongoDB specifically, will remain a versatile foundation for data‑intensive, AI‑driven applications—whether they run in massive data centers or on the edge of a meadow.


Why It Matters

Data is the lifeblood of any effort to understand and protect our ecosystems. For beekeepers, researchers, and AI agents alike, the ability to store, query, and act on massive streams of hive data determines whether we can respond swiftly to threats like heat stress, pesticide exposure, or colony collapse. MongoDB’s flexible document model, proven scalability, and rich ecosystem provide the technical backbone that turns raw sensor readings into actionable knowledge. By choosing the right NoSQL strategy today, we lay a resilient foundation for tomorrow’s AI‑guided conservation, ensuring that both pollinators and the technologies that support them thrive together.

Frequently asked
What is NoSQL Databases And Data Storage about?
The world’s data is exploding faster than any previous generation of technology could have imagined. In 2023, the global data sphere surpassed 97…
What should you know about introduction?
The world’s data is exploding faster than any previous generation of technology could have imagined. In 2023, the global data sphere surpassed 97 zettabytes —roughly the amount of information that could fill 200 million Blu‑Ray discs. Enterprises, research labs, and citizen‑science projects alike are scrambling to…
What should you know about the Evolution of Data Storage: From Relational to NoSQL?
When E.F. Codd introduced the relational model in 1970, the promise was clear: data could be stored in tables, queried with a declarative language (SQL), and remain consistent across transactions. For decades, that model powered everything from banking to airline reservations. Yet the model also imposed constraints…
What should you know about core Principles of NoSQL – The Four Types?
NoSQL is not a monolith; it is a taxonomy of storage models, each optimized for a particular access pattern. Understanding the four primary families helps you decide where MongoDB fits and where complementary technologies might be needed.
What should you know about bSON: The Binary Backbone?
MongoDB stores data as BSON (Binary JSON), a binary-encoded serialization of JSON that adds support for data types not present in plain JSON, such as Date , ObjectId , Decimal128 , and Binary . BSON’s design balances human readability (when converted back to JSON) with efficient storage and traversal. For example, a…
References & sources
  1. Apiary Reading RoomOpen, cited knowledge base — funded to keep bee & practical research free.
From the Apiary Reading Room. Opinion & editorial — not financial advice. We don't overclaim.
More from the Reading Room