51

I am using mongodump from mongo tools to download a backup of my server. However as I run the command, the command returns "Unrecognized field 'snapshot'".

The full error is:

Failed: error reading collection: Failed to parse: { find: "data", skip: 0, snapshot: true, $readPreference: { mode: "secondaryPreferred" }, $db: "xxx" }. Unrecognized field 'snapshot'.

Mongodump --version returns:

mongodump version: built-without-version-string
git version: built-without-git-spec
Go version: go1.7.3
   os: linux
   arch: amd64
   compiler: gc
OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016

I might need to downgrade my version? Otherwise unsure of where to go from here...

  • 1
    What are your versions of O/S and MongoDB server? Your mongodump --version output suggests you have built the tools from source, so it's not obvious what version of MongoDB that might correspond to. Where possible I would suggest downloading the official binaries. – Stennie Aug 22 '18 at 0:22
21

You certainly have a difference of version between mongodump vs your mongoDB server ( 3.6 vs 4.0).

You can use docker to the rescue :

docker run --rm -v $(pwd):/workdir/ -w /workdir/ mongo:4.0 mongodump -h server -d $database --out /workdir/dump/

With docker you can use a precise version of tools cli without install it.

You can even specify an alias (in .bashrc) :

alias mongodump="docker run --rm -v $(pwd):/workdir/ -w /workdir/ mongo:4.0 mongodump"

Note: The folder where the dump is saved will need to have write permissions so the mongodb user in the container can write to the mounted volume. This can be achieved by manually setting the permissions on the dump folder before running the above command.

In the example above that would be: mkdir -m 777 dump. After the dump is completed then permissions can be modified back to a normal (i.e., sudo chmod 755 dump).

| improve this answer | |
  • 1
    I keep getting the error Failed: error dumping metadata: error creating directory for metadata file dump/{COLLECTION}: mkdir dump: permission denied. I tried with -u 0 and -o /tmp/dump, but couldn't get it to work. I finally ended up starting a container, running the dump, then copying it out of the container. Any ideas where I went wrong with the one-liner? – thirdender Dec 7 '18 at 9:59
  • 2
    You need to set the uid appropriately: docker run --rm -v $(pwd):/workdir/ -w /workdir/ -u $(id -u) mongo:4.0 mongodump ... – ltn100 Apr 23 '19 at 9:55
86

Add --forceTableScan

Example:

mongodump --forceTableScan -d database_name -o target_directory

http://aug2uag.blogspot.com/2018/08/mongoexport-unrecognized-field-snapshot.html

| improve this answer | |
  • 1
    Can you please explain what the error is meaning, and why do this argument help so much? – F3L1X79 Nov 22 '19 at 9:26
  • @F3L1X79 see link on this answer – Eido95 Dec 23 '19 at 16:13
  • 1
    This should be the accepted answer. Docker isn't a requirement to solve the issue. – RealHandy Jun 25 at 16:29
1

I was also facing the same issue in CentOS with the below specs where my mongodb authenticated with username and password

enter image description here

I used the below command:

mongodump --forceTableScan -h <mongo database where it is hosted> -u <username>  -d <databasename>  -o /<output directory>/

And entered the mongodb password when prompted.

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.

For more information, just refer this link.

| improve this answer | |
0

If you dump from Mongo Atlas, this should work.

mongodump --forceTableScan --uri "mongodb+srv://username:password@clusteraaa.xxxx.mongodb.net/db_name"  --out "backup-dir"
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.