31

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
  • 1
    I got the same problem, I think it's because I use a mongoexport 3.6.4, with mongoDB server 4.0. – Antoine Aug 22 '18 at 12:55
13

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).

  • 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
  • 1
    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 at 9:55
53

Add --forceTableScan

Example:

mongodump --forceTableScan -d database_name -o target_directory

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

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.