Meteor apps sharing same mongodb

I have problem with connecting admin app to main app database. i have seperate admin app folder and ran

env MONGO_URL=mongodb://127.0.0.1:27017/meteor MONGO_OPLOG_URL=mongodb://127.0.0.1/local meteor run --port 3002

Main app is running on port 3000.

I also tried connecting with port number 3001. But I get same error.
Error:

W20190223-17:18:22.917(5.5)? (STDERR) MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017]
W20190223-17:18:22.918(5.5)? (STDERR)     at Pool.<anonymous> (/home/lelouch/.meteor/packages/npm-mongo/.3.0.11.qol23n.md5bb++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/mongodb-core/lib/topologies/server.js:505:11)
W20190223-17:18:22.918(5.5)? (STDERR)     at emitOne (events.js:116:13)
W20190223-17:18:22.918(5.5)? (STDERR)     at Pool.emit (events.js:211:7)
W20190223-17:18:22.918(5.5)? (STDERR)     at Connection.<anonymous> (/home/lelouch/.meteor/packages/npm-mongo/.3.0.11.qol23n.md5bb++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/mongodb-core/lib/connection/pool.js:329:12)
W20190223-17:18:22.918(5.5)? (STDERR)     at Object.onceWrapper (events.js:317:30)
W20190223-17:18:22.919(5.5)? (STDERR)     at emitTwo (events.js:126:13)
W20190223-17:18:22.919(5.5)? (STDERR)     at Connection.emit (events.js:214:7)
W20190223-17:18:22.920(5.5)? (STDERR)     at Socket.<anonymous> (/home/lelouch/.meteor/packages/npm-mongo/.3.0.11.qol23n.md5bb++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/mongodb-core/lib/connection/connection.js:245:50)
W20190223-17:18:22.920(5.5)? (STDERR)     at Object.onceWrapper (events.js:315:30)
W20190223-17:18:22.921(5.5)? (STDERR)     at emitOne (events.js:116:13)
W20190223-17:18:22.922(5.5)? (STDERR)     at Socket.emit (events.js:211:7)
W20190223-17:18:22.923(5.5)? (STDERR)     at emitErrorNT (internal/streams/destroy.js:64:8)
W20190223-17:18:22.923(5.5)? (STDERR)     at _combinedTickCallback (internal/process/next_tick.js:138:11)
W20190223-17:18:22.924(5.5)? (STDERR)     at process._tickDomainCallback (internal/process/next_tick.js:218:9)
=> Exited with code: 1
=> Your application is crashing. Waiting for file change.

Thank you in advance

Are you sure the mongodb instance is running on this port? What is the output if you type mongo mongodb://127.0.0.1: 27017/ at the terminal?

Meteor mongo says follwing

MongoDB shell version v3.6.4                  
connecting to: mongodb://127.0.0.1:3001/meteor
MongoDB server version: 3.6.4

Port 3001 is not working. Actually admin app is running. but if i change or add new values, its not reflecting in admin app. Am i missing something?

Remove env …should work

1 Like

sorry for late response. It worked. Thank you.

How do i handle this in aws server? I am using mup to delpoy in live?

my main app mup setting

  app: {

    name: 'xxxxxx',
    path: 'xxxxx',

    servers: {
      one: {}
    },

    buildOptions: {
      serverOnly: true
    },

    env: {

      ROOT_URL: 'https://xxxx.com',
      MONGO_URL: 'mongodb://mongodb/meteor',
      MONGO_OPLOG_URL: 'mongodb://mongodb/local'
    },

My sub domain url is admin.xxxx.com and mup setting is

 app: {
    // TODO: change app name and path
    name: 'admin_xxxx.com',
    path: 'admin.xxx.com',

    servers: {
      one: {}
    },

    buildOptions: {
      serverOnly: true
    },

    env: {

      ROOT_URL: 'https://admin.xxxx.co',
      MONGO_URL: 'mongodb://mongodb:27017/app',
      MONGO_OPLOG_URL: 'mongodb://mongodb/local'
    },

What do i give in Mongo URL? where do i give ip address.
Thanks in advance.

`env: {

  ROOT_URL: 'https://admin.xxxx.co',
  MONGO_URL: 'mongodb://mongodbServerIp:27017/ddddd',
  MONGO_OPLOG_URL: 'mongodb://mongodbServerIp/local'
},`

Replace mongodbServerIp by your mongodb server ip address
replace ddddd with your database name, by default it is meteor in dev

If mongodb is on same server, things are pretty easy - but make sure oplog is setup. If you are hosting your own mongodb on a separate server things can be tricky depending on path you are taking. DO has good documentation for that.

I tried all ways regarding connecting to mongodb server.

Error: failed to connect to server [xx.xxx.xxx.xxx:27017] on first connect [MongoNetworkError: connect ECONNREFUSED xx.xxx.xxx.xxx:27017]

Main app is in AWS. I setup inbound rule allowing second app IP and port no.
Same error. I also tried including 0.0.0.0 in ip_bind mongodb.conf. I also tried connecting with main app username and password. Same error. I am been trying for hours to solve this.

This is more of mongo setup. You need to see if you are able to access mongodb from your app server. There is well documented information if googled. Check AWS firewalls it may be blocking.