MongoDB users and roles restore failed

I was trying to restore only mongodb users and roles

Source- os/version- RHEL 7.9, MongoDB shell version: 4.4.5

Target- os/version- RHEL 8.4, MongoDB shell version: 5.0.4

Below are the command I tried and the error I’m getting.

DUMP:

take backup of MongoDB users and roles:

mongodump -u xxxx -d admin -c system.users -p xxx -v --authenticationDatabase admin -o systemusers.bson &> xxx_dump_date "+%Y-%m-%d"_backupoutput.log

– no error registered

RESTORE:

while importing to admin database its shows error.

a. mongorestore -d admin -c system.users -u “xxxx” -p “xxxx” -v --authenticationDatabase “admin” system.users.bson &> xxxx_bsonoutput_dec7.log

2021-12-07T08:43:17.013+0000 checking for collection data in system.users.bson

2021-12-07T08:43:17.013+0000 assuming users in the dump directory are from <= 2.4 (auth version 1)

2021-12-07T08:43:17.013+0000 Failed: the users and roles collections in the dump have an incompatible auth version with target server: cannot restore users of auth version 1 to a server of auth version 5

b. mongoimport -d admin -c system.users -u “xxxxx” -p “xxxxx” -v --authenticationDatabase “admin” system.users.metadata.json &> xxx_users_metadata_jsonoutput_dec7.log

2021-12-07T08:43:55.609+0000 error validating settings: invalid collection name: collection name ‘system.users’ is not allowed to begin with 'system.'

I am, still struggling for fix. Any help will be much appreciated

I am sure that there is no syntatically error in the command…
a. for different version of mongodb can we do this activity?
b. If yes , what are the fixes

Awaiting your response

Hi @Chinmaya_Das ,

I did some testing and it wasn’t working for me either.
I put both db’s at the same version because I thought it was a versioning problem and instead nothing…

I finally managed to find this discussion:

The part that deserves more attention, in my opinion is the following:

You need all of admin to restore that collection successfully.

https://docs.mongodb.com/manual/reference/system-collections/index.html#collections

Why? Users contain roles. So you need roles. The users and roles restore requires the schema version.

All three of those make up the admin database.

hope it helps you.

Regards

ok @Fabio_Ramohitaj
I will do the dump and restore of admin database in target … Will see what happens

it worked…users and roles are restore…

but surprisngly in the restore output log…it says 0 document(s) restored successfully.

please have a look and tell if we can ignore these messages:

although users and roles restores succesfuuly , in log why it is reflecting as 0 document successfully

2021-12-30T08:17:17.854+0000 using write concern: &{majority false 0}
2021-12-30T08:17:17.871+0000 will listen for SIGTERM, SIGINT, and SIGKILL
2021-12-30T08:17:17.871+0000 connected to node type: standalone
2021-12-30T08:17:17.871+0000 The --db and --collection flags are deprecated for this use-case; please use --nsInclude instead, i.e. with --nsInclude=${DATABASE}.${COLLECTION}
2021-12-30T08:17:17.871+0000 mongorestore target is a directory, not a file
2021-12-30T08:17:17.871+0000 building a list of collections to restore from admin dir
2021-12-30T08:17:17.871+0000 found collection admin.system.users bson to restore to admin.system.users
2021-12-30T08:17:17.871+0000 found collection metadata from admin.system.users to restore to admin.system.users
2021-12-30T08:17:17.871+0000 adding intent for admin.system.users
2021-12-30T08:17:17.871+0000 found collection admin.system.version bson to restore to admin.system.version
2021-12-30T08:17:17.871+0000 found collection metadata from admin.system.version to restore to admin.system.version
2021-12-30T08:17:17.871+0000 adding intent for admin.system.version
2021-12-30T08:17:17.871+0000 comparing auth version of the dump directory and target server
2021-12-30T08:17:17.874+0000 system.version document is not an authSchema featureCompatibilityVersion
2021-12-30T08:17:17.875+0000 restoring users and roles of auth version 5 to a server of auth version 5
2021-12-30T08:17:17.875+0000 restoring up to 4 collections in parallel
2021-12-30T08:17:17.875+0000 restoring users from admin/system.users.bson
2021-12-30T08:17:17.877+0000 restoring users to temporary collection
2021-12-30T08:17:17.877+0000 using 1 insertion workers
2021-12-30T08:17:17.911+0000 merging users/roles from temp collections
2021-12-30T08:17:17.922+0000 building indexes up to 4 collections in parallel
2021-12-30T08:17:17.922+0000 0 document(s) restored successfully. 0 document(s) failed to restore.

1 Like

Hi @Chinmaya_Das,
When I tried to do this too, I also saw that 0 documents had been restored, the users also for me had been correctly restored.
But unfortunately I can’t explain why.

Regards