How to Plan Your MongoDB Upgrade
MongoDB 4.4 will reach end of life (EOL) in February 2024, and MongoDB 5.0 will join it in August. If that’s not enough incentive to start planning your MongoDB upgrade, also consider that updating helps eliminate the security and compliance risks that can come from outdated software and offers features that can improve database performance, security and scalability.
Here are some of the new features in newer versions of MongoDB that might make you decide to upgrade sooner than later.
- Live resharding for databases allows users to change shard keys as their workloads and databases evolve without incurring downtime.
- Sharding for time-series collections enhances scalability and performance for temporal data management.
- MongoDB 5.3 introduced clustered collections, which store data based on the associated clustered index keys. This prioritizes query performance over write speed when specific order matters for analytical queries.
- Secondary and compound indexes in time-series collections boost read performance and enable new use cases such as geoindexing.
- Enhanced change streams allow users to access both the previous and current states of modified documents, facilitating tasks like making downstream document updates and referencing deleted ones. This also supports data definition language (DDL) operations, such as creating or dropping collections and indexes.
- Administrators can compress and encrypt audit events before storing them on disk using a Key Management Interoperability Protocol (KMIP)-compliant key-management system.
- The ability to modify time-series data increases flexibility and control.
- New aggregation pipeline operators and variables enable complex data transformations.
- Wildcard indexes improve query performance for faster searches.
- Queryable encryption maintains data confidentiality while allowing querying encrypted data.
How to Plan Your MongoDB Upgrade
Rather than giving you an overly technical guide to upgrading MongoDB, I’ll focus on some best practices that ring true for any MongoDB upgrade, whether you’re spurred on by 4.4 EOL or want to take advantage of the latest and greatest in 7.0. If you’re looking for a more technical, step-by-step walkthrough, you can watch Best Practices for Upgrading MongoDB 4.4.
1. Assess Your Current Environment
Though often overlooked, doing a comprehensive evaluation of your existing setup is essential to minimizing risks and downtime and enabling a smooth, successful upgrade.
It might sound obvious, but start by identifying which version of MongoDB you’re using. Knowing your current version is essential both for determining the gap between your existing setup and the latest version, and selecting the appropriate upgrade path.
Next, evaluate your resources and hardware. For example, do your current servers have sufficient CPU, memory and storage capacities to handle the new version efficiently? And thinking long term, will the new setup meet your future workloads and scaling needs?
Then, understand how you use MongoDB. Is it primarily used for transactional data? Analytical queries? Gaming applications? Different versions of MongoDB may be better suited for specific use cases, so it’s essential to evaluate if the new target version aligns with your database’s intended purpose.
Finally, before undertaking an upgrade, execute a thorough backup of your current data. This includes not just your database’s contents but your application data, customizations, replication configurations, indexes and security settings as well. Percona Backup for MongoDB is an open source community backup tool that can help you back up all of this data.
2. Test, Test and Test Again
Before implementing an upgrade in your production environment, it’s imperative — seriously, imperative — to create a separate sandbox or staging environment that mimics your production setup. Your goal is to identify any issues, conflicts or unexpected behaviors that may arise during the transition. This allows you to catch potential problems in a safe and controlled setting and try to avoid long periods of unexpected downtime.
3. Have a Rollback Plan, Just in Case
You can do all the prep in the world, but unforeseen difficulties happen. Try to find someone with experience doing upgrades to help you, whether they’re a member of your staff or a consultant. At the very least, in case something does go wrong, it’s crucial to have a way to roll back to the previous version of your database.
A comprehensive MongoDB rollback plan typically includes:
- Doing backups of data and configurations.
- Documenting the current state.
- Communicating your plans to key stakeholders.
- Identifying your rollback trigger(s).
- Creating detailed, documented rollback procedures.
- Monitoring your environment.
- Analyzing and understanding what went wrong with the upgrade.
4. Decide Whether to Use a Stable or a Development Version
Stable versions of MongoDB have undergone extensive testing and are deemed production-ready, whereas those still in development may not be fully ready for prime time. Your choice between these versions should be guided by your organization’s risk tolerance and your upgrade’s specific objectives.
5. Determine Your Upgrade Steps and Path
While the upgrade process will vary depending on the individual environment, the general recommended path for a basic MongoDB upgrade is:
- Take a backup.
- Download the new binaries.
- Keep the feature compatibility value (FCV) set to Current/Previous version.
- Shut down Mongo processes in the correct order, in a rolling fashion according to your system type.
- Replace your current binaries with the new binaries.
- Start Mongo processes in the correct order using the rolling fashion required by your system type.
- Wait 24-48 hours (depending on your database) to ensure there are no problems.
- Set the FCV to the new version.
It’s best to conduct the upgrade process slowly and steadily. Progress from your current version through each major release until you’ve reached your intended version. For example, if you are on 4.4, that process would look like 4.4.1+ to 5.0 to 6.0 to 7.0. Do not jump from 4.4 to 7.0.
Once you complete your upgrade, conduct some post-upgrade testing and optimization to ensure your new MongoDB database is running as it should. We’ll cover that in our next article.
If you need assistance with your MongoDB upgrade, Percona can help you create a personalized upgrade plan. Our experts will help you upgrade MongoDB, proactively identifying and mitigating blockers, incompatibilities and potential performance issues during and beyond the upgrade cycle.