When exporting a regular collection, mongodump creates two files inside the dump directory: [name].metadata.json and [name].bson. A single collection can be restored by running mongorestore with the path of the BSON file in the dump directory, i.e. mongorestore dump/test/[name].bson.
However, when exporting a time-series collection, mongodump creates two files inside the dump directory: [name].metadata.json and system.buckets.[name].bson.
If one then attempts to restore the collection by running mongorestore dump/test/system.buckets.[name].bson, this will not strip the system.buckets prefix from the BSON filename. This will result in mongorestore attempting to restore the view namespace in system.buckets.[name] and the buckets namespace in system.buckets.system.buckets.[name], which results in mongorestore failing but also leaving behind a non-functional system.buckets.[name] collection in the database.
Full reproduction steps (example over MongoDB 7.0):
$ mongod --fork --logpath /dev/null
about to fork child process, waiting until server is ready for connections.
forked process: 7105
child process started successfully, parent exiting
$ mongo --quiet --eval 'db.createCollection("ts", {timeseries:{timeField:"t"}}) && db.ts.insertOne({t:ISODate()})'
{
"acknowledged" : true,
"insertedId" : ObjectId("678e0d12a932366358ee79ab")
}
$ mongodump
2025-01-20T08:45:25.722+0000 writing admin.system.version to dump/admin/system.version.bson
2025-01-20T08:45:25.723+0000 done dumping admin.system.version (1 document)
2025-01-20T08:45:25.724+0000 writing test.system.buckets.ts to dump/test/system.buckets.ts.bson
2025-01-20T08:45:25.724+0000 done dumping test.system.buckets.ts (1 document)
$ mongo --quiet --eval 'db.dropDatabase()'
{ "ok" : 1 }
$ mongorestore dump/test/system.buckets.ts.bson
2025-01-20T08:45:41.767+0000 checking for collection data in dump/test/system.buckets.ts.bson
2025-01-20T08:45:41.767+0000 reading metadata for test.system.buckets.ts from dump/test/ts.metadata.json
2025-01-20T08:45:41.783+0000 restoring test.system.buckets.system.buckets.ts from dump/test/system.buckets.ts.bson
2025-01-20T08:45:41.824+0000 finished restoring test.system.buckets.ts (0 documents, 0 failures)
2025-01-20T08:45:41.824+0000 Failed: test.system.buckets.ts: error restoring from dump/test/system.buckets.ts.bson: (BadValue) Invalid namespace: test.system.buckets.system.buckets.ts
2025-01-20T08:45:41.824+0000 0 document(s) restored successfully. 0 document(s) failed to restore.
$ mongo --quiet --eval 'db.getCollectionInfos()'
[
{
"name" : "system.buckets.ts",
"type" : "collection",
"options" : {
"timeseries" : {
"timeField" : "t",
"granularity" : "seconds",
"bucketMaxSpanSeconds" : 3600
}
},
"info" : {
"readOnly" : false,
"uuid" : UUID("e5b00f42-f716-4f4b-9016-cebca9cca289")
},
"idIndex" : {
"v" : 2,
"key" : {
"_id" : 1
},
"name" : "_id_"
}
}
]