-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Critical - P2
-
Affects Version/s: None
-
Component/s: None
-
TAR 2025-05-26
-
2
-
Tools and Replicator
-
0.25
-
Not Needed
ISSUE DESCRIPTION AND IMPACT
We have identified a critical issue in mongorestore where it silently skips restoring any database or collection that has a newline character (ASCII Line Feed, \n, 0x0a) in its name. This occurs without any warning messages being logged. This behavior could lead to silent and permanent data loss if the original backup or source cluster is no longer available.
This issue also affects certain MongoDB Atlas operations that use mongorestore in the backend, specifically when restoring from a backup taken before July 17, 2025 on Flex-tier clusters (including Shared-tier, which has been deprecated); or when pausing a Free-tier cluster.
DIAGNOSIS AND AFFECTED VERSIONS
You may be impacted by this issue if both of the following conditions are true:
- You have a database or collection with a name containing a newline character
- You used mongorestore from MongoDB Database Tools versions 3.3.11 – 100.12.1 to restore from a mongodump backup
On Atlas, you may have been impacted if you have namespaces with newline characters and have either:
- Restored a backup snapshot taken before July 17, 2025, of an Atlas Flex or Shared-tier (M2/M5) cluster.
- Downloaded a backup snapshot taken before July 17, 2025, of an Atlas Flex or Shared-tier (M2/M5) cluster. The downloaded snapshot will have skipped the namespaces with newline characters since Atlas uses both mongodump and mongorestore to generate the backup snapshot.
- An Atlas Free-tier (M0) cluster that was in a paused state before July 17, 2025.
How to find affected namespaces
If you have access to a previous backup (not downloaded from Atlas), you can check for namespaces with newline characters.
- First, ensure you have the latest version of the MongoDB Database Tools (v100.12.2 or later).
- Use this new version of mongorestore to restore the backup to a test or development cluster.
- Connect to your cluster using mongosh and run the following script to identify any databases or collections with newline characters in their names:
- Note - role requirement: A user with the backup role or readAnyDatabase roles will be required in order to execute the script and show all possible namespaces affected
- Running the script using mongosh
- Load the script:
- Option 1: Save the script to a file then load it with `load('path/to/filename.js')`
- Option 2: Copy the script and paste it directly in mongosh shell
- Call the method printNamespacesWithNewlines(); from the mongosh shell
- Load the script:
function printNamespacesWithNewlines() { const adminDb = db.getSiblingDB("admin"); const databases = adminDb.runCommand({ listDatabases: 1 }).databases; var re = new RegExp(/[\n]/) var dbCount = 0; var affected = []; // Array to collect all namespaces print("Namespaces with newline characters (in db or collection):"); databases.forEach(databaseInfo => { thisDbAffected = []; const dbName = databaseInfo.name; if (re.test(dbName)) { dbCount += 1 print(`- database name ${JSON.stringify(dbName)} has newlines so all namespaces in this db are affected.`) } const currentDb = db.getSiblingDB(dbName); const collections = currentDb.getCollectionNames(); collections.forEach(collectionName => { const namespace = `${dbName}.${collectionName}`; if (re.test(namespace)) { thisDbAffected.push(JSON.stringify(namespace)); } }); if (thisDbAffected.length == 0) { print(`- No affected namespaces in database ${JSON.stringify(dbName)}`); } else { print(`- Affected namespaces in database ${JSON.stringify(dbName)}:`) thisDbAffected.forEach(namespace => { print(namespace); affected.push(namespace) }) } print(); }); const nsIncludeString = affected.map(ns => `--nsInclude $'${ns.replace(/^"|"$/g, '')}'`).join(' '); const nsIncludeStringWindows = affected.map(ns => `--nsInclude ${ns.replace(/\\n/g, '`n')}`).join(' '); print("Results:") print(`Affected database names: ${dbCount}`) print(`Affected namespaces: ${affected.length}`) if (affected.length == 0) { print("No affected namespaces found"); } else { print("\n(linux / mac bash) Generated --nsInclude string for affected namespaces:\n") print(nsIncludeString) print("\n(windows powershell) Generated --nsInclude string for affected namespaces:\n") print(nsIncludeStringWindows) } };printNamespacesWithNewlines();
Example outputs:
- If the output shows that there are no affected namespaces, they are not impacted by the issue. For e.g.
Results: Affected database names: 0 Affected namespaces: 0 No affected namespaces found
REMEDIATION AND WORKAROUNDS{}{}
The fix for this issue is included in MongoDB Database Tools v100.12.2 and later.
On-Premises Users:
- Upgrade your tools: Download the latest version of the MongoDB Database Tools here: https://www.mongodb.com/try/download/database-tools.
- Restore missing data: If you have access to the original mongodump backup, and identified affected namespaces using the script above, use the upgraded mongorestore (v100.12.2 or later) to restore the affected databases or collections to your desired cluster.
If the script above returns affected namespaces greater than 0, you could expect to see output similar to the following, in which case you can use the mongorestore command example outlined below to restore those missing namespaces.
Example output:
Namespaces with newline characters (in db or collection): - No affected namespaces in database "admin" - No affected namespaces in database "config" - database name "db-\n-with-newline" has newlines so all namespaces in this db are affected. - Affected namespaces in database "db-\n-with-newline":"db-\n-with-newline.c1" - Affected namespaces in database "db-without":"db-without.coll-with-\n-newline" - No affected namespaces in database "local" Results: Affected database names: 1 Affected namespaces: 2 (linux / mac bash) Generated --nsInclude string for affected namespaces: --nsInclude $'db-\n-with-newline.c1' --nsInclude $'db-without.coll-with-\n-newline' (windows powershell) Generated --nsInclude string for affected namespaces: --nsInclude "db-`n-with-newline.c1" --nsInclude "db-without.coll-with-`n-newline"
Example mongorestore command (from above example):
// linux / mac mongorestore --port 33333 --archive=/path/to/dump --nsInclude $'db-\n-with-newline.c1' --nsInclude $'db-without.coll-with-\n-newline' // windows mongorestore --port 33333 --archive=/path/to/dump --nsInclude "db-`n-with-newline.c1" --nsInclude "db-without.coll-with-`n-newline"
Atlas Users: The mongorestore version used in the Atlas backend has already been upgraded to fix this issue for all future restore and resume operations.
—-----------------------------------------------------
Problem Statement/Rationale
We have noticed a few tenant upgrades that failed to restore certain namespaces with ending newline characters. Newline characters are valid and should be able to be restored. Mongodump does recognize these collections and they are dumped as necessary but not the restore.
In the logs below, mongorestore thinks it is done but when comparing to the mongodump logs, we see that the collection ending with newlines were not restored and no logs indicate any attempt at restoring.
Example logs on atlas prod
Mongodump log: https://cloud.mongodb.com/admin/nds/serverlessDowngradeToFree/67b76767bbbab53a95647858/logs?logType=mongodump
Mongorestore log:
https://cloud.mongodb.com/admin/nds/serverlessDowngradeToFree/67b76767bbbab53a95647858/logs?logType=mongorestore
Steps to Reproduce
Create a collection that ends with a newline character and it should not be restored but it is dumped
Expected Results
All dumped db and collections to be restored
Actual Results
Collections with ending newline characters are not being restored
Additional Notes
This is blocking the completing of forced serverless to free migrations and could potentially become blocker for serverless to dedicated migrations
- is duplicated by
-
TOOLS-2978 Investigate mongorestore failure when restoring namespaces that include newlines
-
- Closed
-
- is related to
-
TOOLS-3895 List any skipped namespaces in mongorestore’s output.
-
- Needs Scheduling
-
-
TOOLS-3896 Avoid mongorestore's namespace-matching logic unless it's needed
-
- Needs Scheduling
-