How to deploy meteor and react app with local mongodb

Hi everyone,
Currently I am creating my first app with meteor and react, and I stacked at the point when I want to deploy it, but cannot. in then imports folder, I have created a collection, and I can access it from both client and server part. in the settings.json file I added the link I got from the mongodb shell - mongodb://127.0.0.1:3001/meteor?compressors=disabled&gssapiServiceName=mongodb, but when I when I run meteor deploy myapp.meteorapp.com --settings settings.json command, I am getting :
/app/bundle/programs/server/node_modules/fibers/future.js:313
hyt36
2020-07-04 17:51:37+02:00 throw(ex);
hyt36
2020-07-04 17:51:37+02:00 ^
hyt36
2020-07-04 17:51:37+02:00
hyt36
2020-07-04 17:51:37+02:00MongoNetworkError: failed to connect to server [127.0.0.1:3001] on first connect [Error: connect ECONNREFUSED 127.0.0.1:3001
hyt36
2020-07-04 17:51:37+02:00 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16) {
hyt36
2020-07-04 17:51:37+02:00 name: ‘MongoNetworkError’,
hyt36
2020-07-04 17:51:37+02:00 [Symbol(mongoErrorContextSymbol)]: {}
hyt36
2020-07-04 17:51:37+02:00}] error.

My question is can i deploy local db? if not , how can I get the records that I already have and import them to the database in mongodb atlas?

Perhaps you could deploy using a docker with a Meteor image that contains the Mongo server or spin a second server and run your own MongoDB. For your existing records, if you go in Atlas, select your cluster and click on the METRICS button, you will indeed get the metrics and you should see a new menu above the metrics (right near the cluster name). The last option in that menu is Command Line Tools. There you have everything you need to move data in and out your Mongo Atlas DB.

Hi @Dena, welcome to the forums!

If you haven’t already, have a read through the Galaxy deployment guide here:

The easiest way to get started is to connect the free tier of Mongo Atlas.

If you want local mongo, you can follow Paulishca’s advice and use a custom docker image that launches a local mongo instance as well.
I’ve never seen this done, and I suspect it would mean you would lose all data on re-deploys and cause inconsistencies when scaling past one container (As the storage in a container is considered ephemeral and will be discarded when the container restarts).
That said, it might be fine for a small demo with a single container, in which case it’s also likely too much effort to get working like this in the first place

Nicee, I fount it. Thx a lot !
now I have to get rid of this message -

.

I am getting this message after I pasted the connection string from mongo atlas in a file in imports folder.
My understanding is if I create a connection with mongo atlas within imports folder then i can access to the collection from both server and client side, right?

Hi :slight_smile: Yeah I have read and followed the guide, but still getting the error that cannot connect.

your mongo URl needs to be provided to your Node environment and not to your running app. There are two ways here:

  1. Your default MongoDB:
    I don’t know where you deploy but in most places (e.g. Galaxy, DigitalOcean, Amazon, Heroku) you have the interface to specify your environment settings. Check this example:

If you don’t have an interface as such, you can add your environment settings right before your meteor run command. Check this: https://docs.meteor.com/environment-variables.html

For Atlas, your URL should look like this:

MONGO_URL: 'mongodb://your_user:your_pass@your_app-shard-00-00-xxx.mongodb.net:27017,your_app-shard-00-01-xxx.mongodb.net:27017,your_app-shard-00-02-xxx.mongodb.net:27017/meteor?ssl=true&replicaSet=Your_Cluster-shard-0&authSource=admin&connectTimeoutMS=60000&socketTimeoutMS=60000',

Just make sure in Atlas, for this project you whitelist all ips and create a read/write user that would be your user to use with the link above.

  1. If you want to connect to a second DB (project) in Atlas, just have the same things in hand: URL, ip whitelisting and user and you can create a collection in this way:
const url = 'mongodb://your_user:your_pass@your_app-shard-00-00-xxx.mongodb.net:27017,your_app-shard-00-01-xxx.mongodb.net:27017,your_app-shard-00-02-xxx.mongodb.net:27017/meteor?ssl=true&replicaSet=Your_Cluster-shard-0&authSource=admin&connectTimeoutMS=60000&socketTimeoutMS=60000'
const _driver = new MongoInternals.RemoteCollectionDriver(url, {})
const your_collection = new Meteor.Collection('your_collection', { _driver })

The set up I have done according to the deployment guid is the following:

  1. I created an account in Mongodb Atlas.
  2. I whitelisted my IP address( I have also tried to whitelist all IP an the result was the same - the same error) & created a new user with read/write rights.
  3. Then I signed in to galaxy.
  4. I created a setting.json file in the roort of my project , and added the connection string I got from mongodb atlas as following :{
    galaxy.meteor.com”: {
    “env”: {
    “MONGO_URL”: “mongodb+srv://my_user:@cluster0-wqmq6.gcp.mongodb.net/?retryWrites=true&w=majority”
    }

}
5. After that ran DEPLOY_HOSTNAME=galaxy.meteor.com meteor deploy myapp_name.meteorapp.com --settings settings.json.
or meteor deploy myapp_name.meteorapp.com --settings settings.json., and all the time I am getting the error - throw(ex);
29g4d 2020-07-02 22:12:49+02:00MongoNetworkError: failed to connect to server [127.0.0.1:3001] on first connect [Error: connect ECONNREFUSED 127.0.0.1:3001 29g4d 2020-07-02 22:12:49+02:00 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1137:16) { 29g4d
2020-07-02 22:12:49+02:00 name: ‘MongoNetworkError’, 29g4d
2020-07-02 22:12:49+02:00 [Symbol(mongoErrorContextSymbol)]: {}
29g4d2020-07-02 22:12:49+02:00}].

Did you try the URL format that I suggested?

Yep, and I am getting the same error.

this FQDN can not be resolved by DNS, that is your problem

1 Like