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:[email protected]/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:
Failed: can't create session: could not connect to server: connection() : auth error: sasl conversation error: unable to authenticate using mechanism "SCRAM-SHA-1": (AuthenticationFailed) Authentication failed.
How can I solve that, and what is SCRAM-SHA-1 –
Peaceful 'export' is not recognized as an internal or external command, operable program or batch file.
I ran the command in the folder where the mongo server is... –
Peaceful © 2022 - 2024 — McMap. All rights reserved.
mongodb://localhost:27017/discordbot
Long one:mongodb://localhost:27017/?readPreference=primary&appname=MongoDB%20Compass&directConnection=true&ssl=false
There is a tab sayingEdition
and it says MongoDB 4.2.15 Community. Hopefully that's the right info. – Peacefuldiscordbot
. I assume this is the database you wish to migrate to Atlas? If so, simply use the mongodump tool to backup the local database, then use the mongorestore tool to restore to Atlas. It is fairly trivial once you have done it before, but if you never have, then you will slog through a mirad of security blocks. Firstly, you must have the mongodump and mongo restore tools. Download them if you don't already have them. – Oshertools
) – Osher