What Is New in MongoDB 3.6
| Category | Key Changes |
|---|---|
| New Features | Change Streams, Retryable Writes, JSON Schema Validation, Tunable Consistency |
| Improvements | Aggregation Pipeline Enhancements, Faster Mongodump/Mongorestore, Improved Index Builds |
| Security | LDAP Authorization, x.509 Certificate Authentication with User Name Mapping |
| Deprecations | MMAPv1 Storage Engine, $isolated Operator, copyCommittedLog Option |
How does MongoDB 3.6 handle real-time data changes?
Change Streams are the headline feature, allowing applications to subscribe to all data changes on a collection, database, or entire deployment. This gives you a real-time feed of inserts, updates, and deletes without the complexity of tailing the oplog. In practice, this enables powerful reactive application patterns and is a game-changer for building event-driven architectures directly on MongoDB.
The streams provide a well-defined API that returns change events in a predictable, ordered format. You can even resume streams using a resume token, which is crucial for handling network interruptions without missing a beat.
What improvements did 3.6 make for data integrity?
JSON Schema Validation allows you to enforce a predefined schema on your collections at the database level. You define rules for document structure, data types, and required fields using a JSON Schema dialect. This is a significant step beyond basic document validation because it uses a widely understood standard.
You can apply validation rules on existing collections using the collMod command or when creating new ones. The validator can be set to warn or error mode, giving you flexibility during schema migrations.
How did write operations become more reliable?
Retryable Writes solve a classic pain point by allowing the MongoDB driver to automatically retry certain write operations if they encounter a network error or replica set failover. This makes applications more resilient without requiring complex retry logic in your application code.
Supported operations include insertOne, updateOne, deleteOne, and findAndModify. The driver handles the idempotency concerns, so you don't have to worry about accidentally creating duplicate documents during a retry.
What new aggregation features were introduced?
The aggregation pipeline gained several powerful new stages and expressions. The $lookup stage was supercharged with support for uncorrelated subqueries and more complex join conditions, moving it far beyond a simple equality match.
New array expression operators like $reduce and $indexOfArray provided much more flexibility for manipulating array data directly within the database. These additions made it possible to handle more complex data transformation logic entirely within the aggregation framework, reducing the need to process data in the application layer.
How did security get upgraded in this release?
LDAP Authorization (Enterprise Feature) allows you to map LDAP groups to user-defined roles on the MongoDB server. This enables centralized user management through your existing LDAP directory, which is a huge win for enterprise deployments already using LDAP.
For x.509 authentication, user name mapping was added, allowing certificates to map to a specific MongoDB user. This simplifies the configuration process for certificate-based authentication schemes, making them more practical for large-scale deployments.
FAQ
Can I use Change Streams with a standalone MongoDB instance?
No, Change Streams are only available when connected to a replica set or sharded cluster. This is because they rely on the oplog, which is a feature of replication.
Are Retryable Writes enabled by default?
Yes, retryable writes are enabled by default in the 3.6 driver when connected to a 3.6+ MongoDB deployment. You can control this behavior through the retryWrites connection string option.
What happens if a document fails JSON Schema validation?
It depends on the validation action you configured. In "error" mode, the operation will fail and return an error. In "warn" mode, the operation will succeed but log a warning message.
Is the MMAPv1 storage engine immediately unavailable in 3.6?
No, it's deprecated but still available. However, it's removed in MongoDB 4.0, so you should start migrating to the WiredTiger storage engine immediately.
Can I use the new $lookup features on a sharded collection?
The uncorrelated subquery feature in $lookup does not work when the from collection is sharded. The classic correlated $lookup (equality match) continues to work with sharded collections.