Failed: error dumping users and roles: error writing data for collection with mongodump

23 June,2020 by Jack Vamvas

Question: I've started the a MongoDB migration using the mongodump module, but when executing the command :

mongodump --username="my_un" --password="my_pw"

I receive the following error message. 

Failed: error dumping users and roles: error writing data for collection `admin.system.users` to disk: error reading collection: Failed to parse: { find: "system.users", skip: 0, snapshot: true, $readPreference: { mode: "secondaryPreferred" }, $db: "admin" }. Unrecognized field 'snapshot'.

I've executed the same command on other installations with no issues? Is there quick fix for this error message?

Answer: I've seen this error before and can be related to the default usage of _id  during scanning collections. The workaround is to use the --forceTableScan switch . 

From the MongoDB documentation:

"By default, mongodump uses the _id index when scanning collections with that index is available (e.g. Views do not have any indexes). Specify --forceTableScan to direct mongodump to scan collection data without the use of the _id index"

mongodump --forceTableScan --username="my_un" --password="my_pw"

Adding the --forceTableScan switch will force mongodump to not use the _id index

Read more on mongodump

How to migrate databases with mongodump and mongorestore

 


Author: Jack Vamvas (http://www.dba-ninja.com)


Share:

Verify your Comment

Previewing your Comment

This is only a preview. Your comment has not yet been posted.

Working...
Your comment could not be posted. Error type:
Your comment has been posted. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Working...

Post a comment on Failed: error dumping users and roles: error writing data for collection with mongodump


dba-ninja.com