0

mongo shell commands are needed to copy a collection from a database on a remote server to local database. Following the instructions as per the docs, The commands to login to the remote database are:

mongo "mongodb://cluster0-shard-00-00-oko1k.mongodb.net:27017,cluster0-shard-00-01-oko1k.mongodb.net:27017,cluster0-shard-00-02-oko1k.mongodb.net:27017/admin?replicaSet=Cluster0-shard-0" --ssl --username <myName> --password

then type my password, then:

Cluster0-shard-0:PRIMARY> use myDatabase
switched to db myDatabase
Cluster0-shard-0:PRIMARY> mongodump -d myDatabase
2017-04-30T07:10:57.698+1000 E QUERY    [thread1] SyntaxError: missing ; before statement @(shell):1:13

How can I move forward from here in order to get myCollection to my local database? thx

Fred J.
  • 5,759
  • 10
  • 57
  • 106

1 Answers1

0

You should run mongodump at the OS command line instead of the mongo shell, and specify your collection name as well as the database:

mongodump --db myDatabase --collection myCollection

mongodump will then create a dump folder, and a subfolder for the database containing the bson for the collection. You can copy that over to where your local database resides.

You can then import it with mongorestore:

mongorestore -d myDatabase -c myCollection myCollection.bson
Joseph Milane
  • 184
  • 1
  • 9
  • mongodump --db mongodb://myUsername:myPassword@cluster0-shard-00-00-oko1k.mongodb.net:27017,cluster0-shard-00-01-oko1k.mongodb.net:27017,cluster0-shard-00-02-oko1k.mongodb.net:27017/myDatabase?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin --collection myCollection gives "-bash: !3: event not found" – Fred J. Apr 29 '17 at 22:14
  • The easiest thing would be to ssh to the remote server if you can. If you can't, there's this post on how to specify the remote host for a mongodump: http://stackoverflow.com/questions/19228474/mongodump-from-remote-server. You'll also need mongodump installed locally if you want to run it remotely. – Joseph Milane Apr 29 '17 at 22:15