7

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?

Annie
  • 229
  • 1
  • 4
  • 14
  • Your mongo-tools (that contains mongoexport) version is incompatible with your mongo server version, you should use the latest version. To migrate data, consider using mongodump/mongorestore, which is generally faster than a json export. – sachav Jun 18 '19 at 21:48
  • yeah I do realize that. Although I have no idea why my db is showing up lower version... I remember when I installed it it was 4 or sth... I am trying to update but have encountered some repo issues. Will try again later. – Annie Jun 18 '19 at 22:11

2 Answers2

21

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
Alex Jolig
  • 10,688
  • 19
  • 103
  • 148
0

so I uninstalled everything mongodb and downloaded the server, shell and tool deb from their website and made sure they're all 4.0.10 for Ubuntu 18.04. Although the same version seems to be included in the synaptic, I decided to go directly install the deb, just in case, as I previously did command line installation and also from Software Manager which ended up having different versions. With versions correctly, I finally can output the json file as I wanted. I would also try the mongodump and mongorestore methods as @sachav mentioned.

Annie
  • 229
  • 1
  • 4
  • 14