Guides — 32 for MongoDB

MongoDB guides

Everything we've written about MongoDB: connections, SQL patterns, imports, clients, and comparisons.

01Connect & How-To

Connect & How-To

Connect & How-ToMongoDB

How to Connect to MongoDB from Ruby

Connect to MongoDB from Ruby with the official mongo driver or Mongoid. Working code for connections, one-client reuse, CRUD, the replaceOne data-loss trap, SRV URIs, authSource, and connection pooling.

6 min read
Connect & How-ToMongoDB

How to Connect to MongoDB from PHP

Connect to MongoDB from PHP with the ext-mongodb extension and the mongodb/mongodb library: the Client lifetime rule, CRUD, SRV strings, Atlas, authSource, pooling, transactions, and the errors you actually hit.

6 min read
Connect & How-ToMongoDB

How to Connect to MongoDB from C# (.NET)

Connect to MongoDB from C# with the official MongoDB.Driver: MongoClient lifetime, async CRUD, the typed vs BSON document APIs, SRV connection strings, Atlas, pooling, LINQ, and the errors you actually hit.

7 min read
Connect & How-ToMongoDB

How to Connect to MongoDB from Java

Connect to MongoDB from Java with the official driver: MongoClient lifecycle, connection strings, one-client-per-app pooling, SRV and Atlas, authentication, and the errors you actually hit in production.

6 min read
Connect & How-ToMongoDB

How to Connect to MongoDB from Go

Connect to MongoDB from Go with the official mongo-driver v2. Working code for one-client-per-app, the v2 Connect signature change, ping-at-startup, connection pooling with SetMaxPoolSize, SRV and Atlas TLS, and BSON struct tags.

6 min read
Connect & How-ToMongoDB

How to Connect to MongoDB from Node.js

Connect to MongoDB from Node.js with the official driver or Mongoose. Working code for connection pooling, the localhost IPv6 trap, SRV strings, and which library to pick.

6 min read
Connect & How-ToMongoDB

MongoDB Capped Collections: Fixed-Size Circular Buffers

How MongoDB capped collections work: creation with size and max, insertion-order guarantees, tailable cursors, the update trap, and why a TTL index is usually the better choice.

6 min read
Connect & How-ToMongoDB

How to Connect to MongoDB from Python

Connect to MongoDB from Python with PyMongo, the PyMongo Async API, or Motor. Working code for connection strings, Atlas SRV URIs, pooling, and the lazy-connection gotcha that hides bad credentials.

6 min read
Connect & How-ToMongoDB

GridFS in MongoDB: Storing Files Larger Than 16 MB

How GridFS works: fs.files and fs.chunks, the 255 KiB chunk model, the GridFSBucket API, sharding GridFS, and when object storage is the better answer.

6 min read
Connect & How-ToMongoDB

MongoDB Time Series Collections: Storage, Bucketing, and Limitations

How MongoDB time series collections work: timeField and metaField, granularity vs custom bucketing, TTL expiry, the metaField-only update restriction, and the long list of limitations to check before committing.

6 min read
Connect & How-ToMongoDB

MongoDB Views: Standard Views and On-Demand Materialized Views

How MongoDB views work: createView syntax, read-only semantics, pipeline and query restrictions, index behavior, and building materialized views with $merge.

5 min read
Connect & How-ToMongoDB

MongoDB Change Streams: Watching Data Change in Real Time

How to use MongoDB change streams to react to inserts, updates, and deletes as they happen, including resume tokens, fullDocument options, pre- and post-images, and the oplog limitations that bite in production.

7 min read
Connect & How-ToMongoDB

Date Operators in MongoDB Aggregations: $dateTrunc, $dateDiff, $dateToString, and Friends

How to bucket, format, parse, and do arithmetic on dates in MongoDB aggregation pipelines, including timezone handling and the boundary-counting behavior of $dateDiff.

6 min read
Connect & How-ToMongoDB

Faceted Aggregation in MongoDB: $facet, $bucket, and $bucketAuto

How to run multiple aggregation pipelines in one pass with $facet, and group documents into ranges with $bucket and $bucketAuto. Syntax, limits, and common mistakes.

7 min read
Connect & How-ToMongoDB

MongoDB Geospatial Queries: 2dsphere Indexes, $near, $geoWithin, and $geoNear

How to store location data in MongoDB with GeoJSON, index it with 2dsphere, and query it with $near, $geoWithin, $geoIntersects, and the $geoNear aggregation stage.

6 min read
Connect & How-ToMongoDB

The $group Stage in MongoDB: Accumulators, Grouping Keys, and Performance

A deep dive on MongoDB's $group aggregation stage: grouping by one or several fields, every accumulator worth knowing, top-N per group, and the memory and index behavior that determines performance.

7 min read
Connect & How-ToMongoDB

MongoDB Projection: Selecting Fields with find() and $project

How to return only the fields you need in MongoDB: inclusion and exclusion projections, the $, $elemMatch, and $slice array operators, aggregation $project, and covered queries.

6 min read
Connect & How-ToMongoDB

Text Search in MongoDB: Text Indexes, $text, and When You Need Atlas Search

How MongoDB text indexes and the $text operator work: creating indexes, weights, relevance scoring with $meta, restrictions, and where Atlas Search fits.

7 min read
Connect & How-ToMongoDB

Working with Arrays in MongoDB Aggregations: $unwind, $filter, $map, and $reduce

When to use $unwind versus the array expression operators $filter, $map, and $reduce in MongoDB aggregation pipelines, with worked examples and performance guidance.

8 min read
Connect & How-ToMongoDB

The MongoDB Aggregation Pipeline Explained

Learn how MongoDB's aggregation pipeline processes documents through sequential stages like $match, $group, $project, and $lookup to transform and analyze data.

7 min read
Connect & How-ToMongoDB

MongoDB Data Types: A Practical Guide to BSON

What BSON is, the data types MongoDB stores, and the ones that trip people up: ObjectId, Date vs Timestamp, the three number types, Decimal128 for money, and how $type lets you query by type.

8 min read
Connect & How-ToMongoDB

MongoDB Indexes Explained

A practical guide to MongoDB index types: single field, compound, multikey, text, wildcard, and more, plus the ESR rule for ordering compound index keys and how to read explain output.

7 min read
Connect & How-ToMongoDB

Joining Collections in MongoDB with $lookup

A practical guide to MongoDB's $lookup stage: the localField/foreignField form, the let/pipeline form for correlated and multi-condition joins, the $unwind pattern, and performance considerations.

6 min read
Connect & How-ToMongoDB

MongoDB Query Operators: A Practical Guide

How to filter documents in MongoDB with comparison, logical, element, array, and evaluation operators, including $in, $or, $elemMatch, $exists, and $expr.

6 min read
Connect & How-ToMongoDB

MongoDB Schema Design: Embedding vs Referencing

How to decide between embedding related data in one document and referencing it across collections in MongoDB, covering the 16MB limit, access patterns, cardinality, atomicity, and the common hybrid patterns.

6 min read
Connect & How-ToMongoDB

MongoDB Transactions: Multi-Document ACID Explained

When you need multi-document transactions in MongoDB, when you do not, and how to use them correctly: sessions, startTransaction, the 60-second limit, retryable errors, and why a good schema needs them less often than you think.

6 min read
Connect & How-ToMongoDB

MongoDB Update Operators: A Practical Guide

How to modify documents in MongoDB with $set, $inc, $unset, and array operators like $push, $pull, $addToSet, and the positional $ and $[] operators.

6 min read
← All guides