Max.H
Max.H

Reputation: 33

mongoDB clone collection from database A to remote database B

I need to clone a collection from my db called 'company', collection is called 'company' from example: mongodb.example.net:27017.

I tired to run this, but kept a SyntaxError: missing ; before statement { cloneCollection: "company.company", from: "host.domain.com:27017" }

If I try db.cloneCollection('mongodb.example.net:27017','company') The return shows as {"ok" : 1}

When I check my collections, nothing appears.

Any ideas how to clone a collection from one DB to another DB?

Upvotes: 1

Views: 801

Answers (1)

Saleem
Saleem

Reputation: 9008

There are few steps you need to follow:

Assuming you are connected to local server via mongo shell.

  • use "remote_database_name"
  • db.cloneDatabase("remote_server")

Make sure you have proper access to remote MongoDB server too. Also make sure there is no existing local database with same name as of remote db you are trying to clone. Please see more information here

Upvotes: 2

Related Questions