Domanda

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

È stato utile?

Soluzione

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

Altri suggerimenti

Add --forceTableScan

Example:

mongodump --forceTableScan -d database_name -o target_directory

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

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.

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"
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a dba.stackexchange
scroll top