Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongoexport error: Failed: Failed to parse + Unrecognized field 'snapshot

Goal:to migrate my local mongodb data to mongobd atlas cluster.

Try:
1. export local data as json.
2. import json to cluster.

OS: Linuxmint 19.1 Cinnamon
mongo --version MongoDB shell version v4.0.10
mongod --version db version v3.6.3
I also have a separate database folder.

So first I started

/home/me/mongodb/bin/mongod --dbpath=/home/me/mongodb-data

then I opened a terminal and typed

~/mongodb/bin $ mongoexport  --db task-manager --collection users --out ~/Desktop/test.json

I expected the users collection from task-manager database will print out as a test.json file but I am getting the error:

2019-06-18T22:05:06.108+0200    connected to: localhost
2019-06-18T22:05:06.108+0200    Failed: Failed to parse: { find: "users", filter: {}, sort: {}, skip: 0, snapshot: true, $readPreference: { mode: "secondaryPreferred" }, $db: "task-manager" }. Unrecognized field 'snapshot'.

What's wrong and what should I do to fix it? Is there any better way to migrate data?

like image 558
Annie Avatar asked Jun 18 '19 20:06

Annie


2 Answers

This usually happens due to different versions of mongodump vs your mongoDB server.

But adding --forceTableScan switch can solve the problem

mongodump --forceTableScan -d database_name
like image 61
Alex Jolig Avatar answered Nov 24 '22 11:11

Alex Jolig


This is due to the mongo snapshot functionality which was introduced in mongo 4.0 You will face this if mongo client is below 4.0 and db is on above 4.0 You can fix this by two option:

  1. using --forceTableScan
  2. download the latest mongo client as per your OS and fire the command, you should not see the error Note: same things happens to mongodump
like image 37
Vaseem007 Avatar answered Nov 24 '22 11:11

Vaseem007