Clone mongoDB collections - mongodb

I have different servers with mongoDB in it.
What is the best way to clone one collection from one server to another ?
I did use mongodump (using Studio 3T) and create a BSON archive of the collection I want to copy on the another server.
To do so I did log in as admin of the mongoDB server to copy and created the BSON archive.
Then I did login in the other server as admin as well and tried to import the BSON archive but is always end up with : error reading database: not authorized on to execute command.
I did add the admin credential of the first server on the second server as well and logged in with the same credentials.
What would be the correct way to clone/duplicate a collection from one server to another ?
Thanks

I was finally able to clone a db between two servers. Had to play with some user roles, granting roles before not assigned to the user from who created the system. So at least this is solved, now I'm working to actually be able to use the cloned db. Thanks

Related

Copy data from Postgres DB (GCP Project A) to another Postgres DB (GCP Project B)

I would be happy to get your help / feedback re data load.
Goal:
Load source data from a Postgres database, which is located in GCP project A to another Postgres database, which is located in GCP project B.
Challenge:
Get a connection (I have an IAM account with sufficient rights to run a COPY TO / COPY FROM command) to the Postgres DB in GCP Project A and copy the table either to a CSV or create a dump that can be used in order to be inserted to another Postgres DB in GCP Project B.
How do I connect to the database (e.g. if I create a key, where shall I store the json keyfile and would that approach even be feasible?) with this IAM email account?
Other ways I've researched were to use psycopg2 (thus I could use the function cursor.copy_expert (which doesn’t need any superuser right or Postgres user credentials and copy the data), but I didn’t succeed in connecting to the database with psycopg2 due to challenges with cloud proxy.
Another idea was to use pg_dump or gcloud sql export csv.
I would be curious if some of you were facing a similar challenge and how did you solve it and what might be the best way/practice
You can have a try out database migration service. You can set up a continuous migration configuration and use Cloud SQL for PostgreSQL.
Hello after a lot of searching I've come to these solutions:
If you have continuous copy, you need to use the database migration service, check this documentation.
If you have one shot copy:
you can restore your instance, see the bottom page of this documentation
you can create a bucket and backup your instance on it, then import it from the other project

How to transfer a database from MongoDB Compass to MongoDB Atlas

I have an existing database for a discord bot in MongoDB Compass v1.28.1 I want to transfer all the data in the database to mongodb atlas because of its more extensive functionality and to not have to wait for compass to take ages to load each time I open it. However when I follow the steps to connect that are provided in Atlas, the pop-up that's supposed to appear when I copy a path to the clipboard doesn't appear, and nothing happens. I tried to connect through my app in VSCode, the same way I did for Compass, using mongoose. Still no collections are loading or any data being stored. I have made my schemas etc. which work perfectly fine in Compass...
Migration to Atlas is documented at https://docs.atlas.mongodb.com/import/
To save you some reads, you have to options - export/import and mongodump/mongorestore.
I would recommend to try export/import first. It's built into Compass https://docs.mongodb.com/compass/current/import-export/ and must be simpler to use considering limited experience with mongo. It's UI oriented so just follow the click-through guide in the documentation.
Unfortunately it has some limitations related to data type conversion from BSON to JSON and may be a bit tedious if you have large number of collections.
In this case you will need to follow CLI mongodump/mongorestore way #barrypicker suggested in the comments. Both commands are available in cmd and PowerShell consoles.
First you backup your local database https://docs.mongodb.com/v4.2/reference/program/mongodump/:
mongodump --uri="mongodb://username:password#localhost:27017/discordbot"
username and password are the ones you use in compass to connect to the source database.
It will create dump directory with all collections you have.
Then you have to upload the backup to Atlas:
mongorestore --uri="mongodb+srv://username:password#cluster.tenant.mongodb.net/database" dump/
username and password are the ones you use to connect to atlas cluster, listed in the "Security/Database Access" section.
You can get the exact subdomains for the --uri part from Atlas. In the dashboard click "Connect" button for the cluster you want to connect to, then choose "shell" as the connection method in the connection pop-up:

Meteor - unmount existing mongo collection

We are creating Meteor-based Mongo database manager and we need the ability to "unmount" (remove from system) all collections when we switch databases.
Example:
I'm managing database called dbA. We have all collections for that database created using Mongo.Collection() on server and on client side.
I want to switch database to dbB. I need to unmount all Collections of dbA and mount those of dbB. Reason: dbB could have a collection of the same name as dbA (and usually does)
Is there a way to do this?
Thanks!
You may be able to accomplish this by publishing the necessary data from the new database.
Here's a discussion from a similar question on the Meteor Forums (note the proposed solution at the end):
https://forums.meteor.com/t/switch-database-while-meteor-is-running/4361/5
hi i think you can do with
db.copyDatabase()
run the shell command in the backend from meteor server and execute the copy database command. and after the database is copied you can remove the previous collection.
more detail about copyDatabase() is here
https://docs.mongodb.org/manual/reference/method/db.copyDatabase/

connecting to remote mongo db server and running clone

I am migrating from server OLD at the old hosting company to server NEW at the new hosting company.
I want to run the clone command so I clone the mongoDB from OLD to NEW.
For OLD:
The public ip address is: 44.55.66.77.
The machine login user name is: admin, and the password is password
What is the right way to do this?
So far I can't even log into the server OLD
So far I have tried the following command prompts on NEW:
mongo -u admin -p password 44.55.66.77
mongo remote-ip:44.55.77.66 -u admin -p password
That don't work
I also tried this from mongo shell:
db.CopyDatabase('OldDb', 'NewDb', '44.55.66.77', 'admin', 'password')
and I get: the "could not connect to server" error message
Aside from firewall considerations in order to copy data between MongoDB servers, db.copyDatabase() (aka the copydb command) has a number of important usage caveats including:
copydb does not produce point-in-time snapshots of the source database; writing data to the source or destination database during the copy process will result in divergent data sets
copydb does not lock the destination server during its operation, so the copy will occasionally yield to allow other operations to complete.
There is also a known issue that copydb may not work with the role-based privileges in MongoDB 2.4 if you have authentication enabled (see SERVER-8213, which was recently fixed in the 2.5.x development releases).
A much better approach to migrating your data would be to restore from a normal backup using mongodump/mongorestore or file system snapshots. The Backup & Recovery section of the MongoDB manual has tutorials covering procedures for different deployment types.

not able to connect to mongodb because of unauthorized lock type

I am trying to connect to my mongodb deployed in jelastic cloud
If i try to use the test database already provided in the mongodb node in jelastic..it works fine.But if i create my own database and try to access the collections created in it ..i get the following exception
com.mongodb.MongoException: unauthorized db:appdb lock type:-1 client:192.168.1.53
Why is this happening?how can i resolve it?
I am reading the configuration from a file mydb.cfg
host=mongodb-***.jelastic.servint.net
dbname=appdb
user=admin
password=*****
When in Rock Mongo web interface pick the targeted db and go for 'More' in config panel.
This has to show you the list of users having rights for DB.
Did you set the user and rights for your custom collection?
Try to check the configuration under 'Authentication' section?
Anyway, supposedly admin user should have rights to all DBs. You can try to figure this issue out at Jelastic community
I had the same issue when connection to mongodb custom named database.
In order to succeed with the connection, I have created an user for my custom named database.
(I added the provided admin user with its password to the authorized users as the image shown).