10

I've recently deployed my Meteor app to a Digital Ocean droplet running Ubuntu 14.04 x32. I used Meteor Up with this mup.json file:

{
  // Server authentication info
  "servers": [
    {
      "host": "mycorrecthostname",
      "username": "root",
      "password": "mycorrectpassword"
    }
  ],

  // 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.25 by default. Do not use v, only version number.
  "nodeVersion": "0.10.28",

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

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

  // Location of app (local directory)
  "app": "/my/correct/path/to/app",

  // Configure environment
  "env": {
    "ROOT_URL": "http://mycorrecturl.com"
  },

  // 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": 15
}

Everything works great. I have tested the website, and everything works just the way it should. I've also set up my ssh keys with the server, and can ssh to it without a password.

Now though, I need to access my server database remotely. I have some local data in a python shelf file that I need to seed my database with. I understand how to connect to a remote database with pymongo, but I'm trying to get a connection URI with meteor mongo --url http://mycorrecturl.com/ and it just returns this error:

Couldn't open a mongo connection: Site does not exist

What?? What is going wrong here? I would expect it to ask for authentication, but just not existing? Officially confused.

Your help is appreciated in advance!

Update

I've been hunting around in my server directories, trying to successfully run meteor mongo there, but despite the fact that I've installed meteor with curl https://install.meteor.com | /bin/sh, it simply always says that I'm not in a meteor project directory. Even the hidden .meteor directory apparently wasn't a project directory.

Update

I've looked more closely at the Meteor Up docs, and it says this:

You can't access the MongoDB from the outside of the server. To access the MongoDB shell you need to log into your server by SSH first and then run the following command.

mongo appName

I tried that out and it works, but that's not good enough. I need to be able to access the database remotely. Is it simply impossible with a Meteor Up deployment?

One of the answers below seems to be suggesting that by setting the MONGO_URL in my env object, that I will basically be manually telling the database what url to respond to. Is that accurate?

Update

The Meteor Up docs say the following:

<appName> is the name of the database

So, on the advice of one of the answers, I edited my mup.json to include this:

// Configure environment
"env": {
  "ROOT_URL": "http://localhost/",
  "MONGO_URL": "mongodb://root:[email protected]:27017/meteor"
  // My appName is "meteor", so that is the name of the database as well.
}

When I execute mup deploy with those variables, the deployment fails. Here's the first part of the error (if you'd like to see the rest let me know):

/usr/lib/node_modules/wait-for-mongo/bin/wait-for-mongo:14
    throw err;

When I use mup reconfigure, it doesn't fail, but then the website simply cannot be found at it's url. It seems to me that the MONGO_URL isn't a control mechanism, but merely a pointer to an outside database such as mongohq.

I'm thinking I'll have no choice but to resort to the mongo appName convention and an ssh python library, but I'd love to find a way to directly access my database remotely and still keep using Meteor Up.

7 Answers 7

7

It is impossible to remotely access the database, if Meteor Up installed and set it up for you. From the Meteor Up docs:

You can't access the MongoDB from the outside of the server. To access the MongoDB shell you need to log into your server by SSH first and then run the following command.

mongo appName

It can however be accessed in other ways than that mongo appName interface, if those programs are running on the server.

Digital Ocean Ubuntu droplets come equipped with Python 2.7, so using pymongo is possible. This command will connect you:

from pymongo import MongoClient
client = MongoClient()

That will automatically connect at mongodb://localhost:27017/

pymongo isn't a default package, so install pip, and then use pip to install pymongo.

apt-get install python-pip python-dev build-essential
pip install pymongo
3
  • You show it for Python, but how can we connect to the MongoDB locally via Java?
    – FullStack
    Commented Mar 6, 2015 at 6:39
  • If anyone comes accross this and is on DO and has already deployed. use
    – mjwrazor
    Commented Apr 25, 2016 at 23:54
  • If anyone comes accross this and is on DO and has already deployed. cd into your project: where your project code is. Then 'show dbs' : shows your databases. 'use databseName' now you can 'show collections' now you can db.collectionName.find() and any mongodb functions.
    – mjwrazor
    Commented Apr 26, 2016 at 0:49
4

It's because you did not set the MONGO_URL in the "env" object.

// Configure environment
"env": {
    "PORT": 58090, # Your application port
    "ROOT_URL": "http://localhost/",
    "MONGO_URL": "mongodb://username:[email protected]:27017/myDatabase",
    "METEOR_ENV": "production"  # If you need to separate your local environment from production
},

Then, just run mup deploy.

4
  • Wait really? I actually have control over what the MONGO_URL should be? It seems to me that since Meteor Up installed the database for me, it would just choose a URL. I'm confused about the actual purpose of the env variable. Could you point me in the direction of more info?
    – blaineh
    Commented May 21, 2014 at 20:44
  • And what exactly does myDatabase point to? Some sort of configuration file?
    – blaineh
    Commented May 22, 2014 at 15:11
  • MyDatabase is name of your database. You need to specify a MONGO_URL to allow your meteor application to connect to Mongo. Check Step 9 of this tutorial, it should help you to understand (it is not using Meteor Up though). Commented May 22, 2014 at 15:36
  • Check my edit. Meteor Up docs say that the database name is the same as the appName. I made that adjustment but it had the exact same result. I'm thinking I'll just have to resort to some sort of ssh tool. Meteor Up docs even say this: "MongoDB installed and bind to the local interface (cannot access from the outside)". That article you sent me (although containing extremely valuable information!) just doesn't apply in this case.
    – blaineh
    Commented May 22, 2014 at 16:05
2

It took me a while to figure this out. It is not possible to access the mongodb server from outside your hosting server. Therefore, you have to ssh into your server first and work from there. To connect to your db with pymongo, use the following:

client = MongoClient('mongodb://localhost/APPNAME')
posts = client.APPNAME.posts

APPNAME should be specified in your mup.json file and replace posts with whatever collection you must update.

2

I think I found a solution for accessing the DB with mupx on a digitalocean ubuntu 14.04 server.

After deployment of your app with mupx, do the following:

Login with ssh into your server, then install mongo: apt-get install mongodb

Then run the mongo command on your server. Try checking if your DB exists by running show dbs. If it is, then use yourdbname. It should hold all the data from your running app!

Let me know if it works. Good luck.

1

I had this some problem but was able to use 3T MongoChef to do it. There is an option in MongoChef to connect to a DB via SSH and it worked like a charm. Hope this helps others out.

Here is the relevant screen in MongoChef from where you can do this. enter image description here

0

You can change the mongod.conf, to allow access from outside (a bit dangerous of course ;)

nano /etc/mongod.conf

# Listen to local interface only. Comment out to listen on all     interfaces.
# bind_ip = 127.0.0.1

then restart the server

service mongod stop
service mongod start

and you can access it from outside (using ssh-forwarding in robo-mongo)

0

All I did was add the IP of my Digital ocean droplet server, instead of localhost, and it worked:

env: {
      ROOT_URL: 'http://yourdomain.com',
      MONGO_URL: 'mongodb://104.236.24.66:27017/meteor',
      PORT: 3002,
    },

Using this mongo instance in docker for 2 meteor apps currently.

EDIT: This depends on how your firewall is setup. Check with "ufw status". Also depends on how your mongo is deployed (which ports forwarded to where; ex) 0.0.0.0:27017->27017 ).

Not the answer you're looking for? Browse other questions tagged or ask your own question.