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

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

 

Author: Jack Vamvas

Leave a Reply

Discover more from ciquery

Subscribe now to keep reading and get access to the full archive.

Continue reading