Share mongodb between apps


#1

Hi,
I have configured two meteor applications to work both on the same ec2 server with two sub-domaine:
admin.my-dom.co and app.my-dom.co
Thanks to nginx i am able to run the whole stuff perfectly except having some issue with mongo,

the purpose of the admin.my-dom.co is to connect to the same mongodb database already used on app.my-dom.co,

I have tried many example and many link found on google especially this how-to-use-the-existing-mongodb-in-a-meteor-project and this env var

but unfortunately the admin app is still using it’s proper database,

I am using mupx to deploy and This is how my json look like:

 {
  // Server authentication info
  "servers": [
    {
      "host": "my-ip",
      "username": "ubuntu",
      //"password": "password"
      // or pem file (ssh based authentication)
      "pem": "~/.ssh/aws.pem",
      "env": {
        "PORT": 3000,
        "MONGO_URL": "mongodb://ubuntu@my-ip:27017/my-dom"
      }
    }
  ],

  // Install MongoDB in the server, does not destroy local MongoDB on future setup
  "setupMongo": true,

  // WARNING: Node.js is required! Only skip if you already have Node.js installed on server.
  "setupNode": true,

  // WARNING: If nodeVersion omitted will setup 0.10.36 by default. Do not use v, only version number.
  "nodeVersion": "0.10.40",

  // Install PhantomJS in the server
  "setupPhantom": true,

  // Show a progress bar during the upload of the bundle to the server. 
  // Might cause an error in some rare cases if set to true, for instance in Shippable CI
  "enableUploadProgressBar": true,

  // Application name (No spaces)
  "appName": "admin",

  // Location of app (local directory)
  "app": "/var/www/admin",
  "env": {
    "MONGO_URL": "mongodb://ubuntu@my-ip:27017/my-dom",
    "PORT": 3000,
    "ROOT_URL": "http://admin.my-dom.co"
  },
  // Meteor Up checks if the app comes online just after the deployment
  // before mup checks that, it will wait for no. of seconds configured below
  "deployCheckWaitTime": 60
}`

Thanks,
Ahmed


#2

Try setting setupMongo to false to force mup to expect a MONGO_URL.


#3

Thanks for the fast reply,

i updated setupMongo to false, redeploying and i got this error (mupx logs --tail=50):

[object Object]
[54.186.213.175]     at Object.Future.wait (/bundle/bundle/programs/server/node_modules/fibers/future.js:398:15)
[54.186.213.175]     at new MongoConnection (packages/mongo/mongo_driver.js:213:1)
[54.186.213.175]     at new MongoInternals.RemoteCollectionDriver (packages/mongo/remote_collection_driver.js:4:1)
[54.186.213.175]     at Object.<anonymous> (packages/mongo/remote_collection_driver.js:38:1)
[54.186.213.175]     at Object.defaultRemoteCollectionDriver (packages/underscore/underscore.js:750:1)
[54.186.213.175]     at new Mongo.Collection (packages/mongo/collection.js:102:1)
[54.186.213.175]     at AccountsServer.AccountsCommon (accounts_common.js:23:18)
[54.186.213.175]     at new AccountsServer (accounts_server.js:16:5)
[54.186.213.175]     at Package (globals_server.js:5:12)
[54.186.213.175]     at /bundle/bundle/programs/server/packages/accounts-base.js:1814:4

It look like meteor can’t connect to the mongo database


#4

Any chance to run two meteor apps with the same containered database ?


#5

No, not with mupx (at least not easily). From the mupx docs:

MongoDB installed and bound to the local interface (cannot access from the outside)

There are hacks to get around this but they aren’t pretty. I’d recommend instead looking into hosting a separate Mongo DB instance somewhere, then connecting to this separate DB from both apps. You can set this up yourself using something like a DigitalOcean Droplet, or look into using a hosted Mongo DB solution like compose.io or mLab.


#6

Thanks again for your reply but i am still very stacked
i am runing the two app on the same server so i don’t think i have the same issue (Access from the outside)
My question is why it work for the main app and not for the second ?
This is very strange


#7

Strange, i have deployed a new version with a remote url and i got the same error !
I have also installed the so simple todo https://www.meteor.com/tutorials/blaze/creating-an-app but i got also the same error:

[54.186.213.175] /bundle/bundle/programs/server/node_modules/fibers/future.js:300
[54.186.213.175] 						throw(ex);
[54.186.213.175] 						      ^
[54.186.213.175] [object Object]

The mongo instance successfully runned and i can login to the mongo shell
This is my pre online deployement and am realy confused about all of those errors :frowning:


#8

Just to add to this discussion, I have 2 separate apps running from one Mongo DB, but Mongo is on a separate machine (one is a test version of a site, another is production). Works without issue but yeah, you’d need Mongo to be on another machine and tell mupx NOT to install mongo.

It should just work then. Make sure the mongo_url is set properly and you’re good to go.


#9

Thanks Korus i have now excatly what you have done
(2 separate apps connected to a mongo instnace on ec2 )
what’s the fibers error mean ?
This is my mongo string in mup.json:
“setupMongo”: false,
“setupNode”: true,
“nodeVersion”: “0.12.0”,
“MONGO_URL”: “mongodb://dummyadmin:dummypass@my-ip:27017/todos”

Any clue ?


#10

You may need to accept connections on the Mongo machine from the IP of your apps. I vaguely remember having to set up Mongo / the server to accept direct connections.

Here’s some useful info on it: http://www.mkyong.com/mongodb/mongodb-allow-remote-access/

Also, node version I see you have set to 0.12.0. Is there a reason for that? Mine is set to 0.10.43.


#11

Thanks to ec2 security group:
Opening port: Custom TCP Rule TCP 27017 my-admin-app-ip/0
I also edited /etc/mongod.conf to set bindIp: 0.0.0.0

For nodejs thereis no real reason for version updating , it’s just a small check if newer node version can resolve the issue.


#12

Ah ok, fair enough then. Are you all sorted now?


#13

ok,to resume there are two differents issues on this ticket
The first one was sharing a containred mongodb instance with two apps all of them on the same server => got no solution at least for now.

the second with connecting a meteor app to an external ec2 mongo instnace (The recommanded way) => i finaly got it !
i made a mistake on reading the logs :blush: the exact error was: Failed to authenticate
So i added an admin user to the right mongodb schema (not easy at all lol) and it should be fine now

Thanks a lot for your support and i hope it hasn’t been a wast of time for you guys


#14

It is possible to deploy two apps using mupx and share the same db on a single box.

In your mup.json, you had:

What you need to do is to replace ubuntu@my-ip with mongodb (mupx doens’t set up a database on the ubuntu instance, it sets one up in a docker container on the ubuntu instance (the container is called mongodb).

i.e. replace the whole line above with:

"MONGO_URL": "mongodb://mongodb:27017/my-dom"

This will point to the mongo instance running in the existing mongodb container.

And it’s probably best to have "setupMongo": false when running mupx setup, to avoid restarting the mongodb container. Although that’s not a big deal unless you’ve started a replica set inside the container (so you can use the oplog) but, from your mup.json file, it doesn’t look like you’re doing that so no problem whether setupMongo is true or false.


#15

I have have some problems with configuring two meteor applications. Could it be by the reason of using proxies (http://advanced.name if it matters) and change ip?


#16

I am using nginx on top off two meteor instance and it worked,
What is exactly your problem ?