Migrate data

Whitelist your IP in Moralis

In order to access your MongoDB you need to whitelist your IP address:

Login to your account, and navigate to the Database tab of  your dappLogin to your account, and navigate to the Database tab of  your dapp

Login to your account, and navigate to the Database tab of your dapp

Whitelist your ip and save your configWhitelist your ip and save your config

Whitelist your ip and save your config

Copy the ip address of your MongoDB. You need this in the next stepCopy the ip address of your MongoDB. You need this in the next step

Copy the ip address of your MongoDB. You need this in the next step

Connect directly to the hosted Moralis MongoDB

You can connect to the MongoDB that is hosted on Moralis via different methods:

A. Using scripts

const { MongoClient } = require('mongodb');

const MONGO_HOST = 'MONGO_HOST_IP_FROM_ADMIN_INTERFACE';  
const MONGO_PORT = 'MONGO_HOST_PORT_FROM_ADMIN_INTERFACE';

// Create a new MongoClient  
const client = new MongoClient(`mongodb://${MONGO_HOST}:${MONGO_PORT}`);

async function run() {  
  try {  
    // Connect the client to the server  
    await client.connect();  
    // Establish and verify connection  
    await client.db('admin').command({ ping: 1 });  
    console.log('Connected successfully to server');  
  } finally {  
    // Ensures that the client will close when you finish/error  
    await client.close();  
  }  
}  
run().catch(console.dir);
import pprint  
import pymongo

MONGO_HOST = "MONGO_HOST_IP_FROM_ADMIN_INTERFACE"  
MONGO_PORT = MONGO_HOST_PORT_FROM_ADMMIN_INTERFACE

con = pymongo.MongoClient(MONGO_HOST, MONGO_PORT)  
user_table = con['parse']['_User']  
pprint.pprint(user_table.find_one())

After you have established direct access to Mongo DB, you You can do your own dumps for the database.

📘

_User table is a particular example of table that starts with _, most of the tables will not start with _

Using Compass

You can use Compass to interact with MongoDB using a tool with an interface.

Insert your MongoDB IP address and connectInsert your MongoDB IP address and connect

Insert your MongoDB IP address and connect

Now you are connected to the MongoDB that is hosted on Moralis. For reference on how to export data, see https://www.mongodb.com/docs/compass/current/import-export/.

Import data

To import data, you can use the same methods as in the previous step. You can use a script, or connect via Compass. The difference is that you will need to provide the DATABASE_URI of your server that you have specified in your .env.


Did this page help you?