Mongorestore cannot import databases with a colon in the name

I am trying to migrate data from one Mongo instance to another using mongdump/restore. The dump is fine but the restore doesn’t like that I have colons in the database names:

error creating collection aaaa:bbbb.col: error running create command: 
Database name {aaaa:bbbb} contains one or more invalid characters. 
Unsupported Characters are {[/\\."$*<>:|?]}

I would have expected mongo to have refused to create the source databases if the colon is illegal. I also note that the docs place relatively few limits on the db name.

Is there anything I can do or will I have to write a script to do it the long way?

mongorestore version: 100.9.4 (same for dump)
git version: ce6af0fefca324ad5d9cb689d335130f48c99699
Go version: go1.20.12
   os: linux
   arch: amd64
   compiler: gc

I would try a few things.

1 - Manually create the database aaaa:bbbb before mongorestore. Perhaps, it cannot create it but it may be able to use it.


2 - Use --nsTo/–nsFrom to restore into a database name that is acceptable. Then once it is restored, use an aggregation that $out to your previous name.

Thanks - but I have 250+ DBs so that’s slightly impractical, methinks. :frowning:

When I write manually, this does not exclude writing scripts.

I am closing - not a mongorestore issue after all but a restriction in AWS serverless MongoDB. Cannot create db in mongosh either.

Thanks for suggestions, however.

1 Like