How to use Mongochef to connect to a Meteor site hosted on meteor.com

If you’re developing a website in Meteor, you may be using a free site on meteor.com for testing. It’s really useful to be able to connect to the live database using a visual tool such as MongoChef, but I found it a bit tricky at first so here are my notes.

First, install a Mongodb GUI tool. Make sure the tool you choose supports Mongodb version 3, and make sure you correctly choose either the 32bit or 64bit version depending on your development machine. The rest of this tutorial assumes you are using the free version of MongoChef.

Note: don’t try to use RoboMongo. Since Meteor updated their free servers to run Mongo shell 3.0, RoboMongo can’t connect to them – and nor can the version of Mongodb (Mongo shell 2.6.7) that ships with Meteor by default, as explained in this forum post.

Run MongoChef. By default, the Connection Manager dialog should open.

Click “New Connection”. Enter a name for your connection, anything that will remind you what site it connects to.

Now you need to get some information about your Meteor site. To connect, you’ll need firstly the server, port and database name, and then a set of login credentials. You don’t know any of these but don’t worry you can easily find out.

Open a terminal window and navigate to your Meteor project directory. Run this code:

meteor mongo --url mysite.meteor.com

Make sure to replace ‘mysite.meteor.com’ with the actual address of your site. The terminal may ask you to log in to your Meteor developer account.

Wait a few seconds and a line of text should appear in the terminal, looking something like this:

mongodb://client-d5ba2e88:9cc999cb-9e08-8e63-2c98-ffc3f11a7792@SG-mother1-6243.servers.mongodirector.com:27017/mysite_meteor_com

This contains all the information you need to connect, and breaks down like this:

mongodb://username:password@server:port/databasename

The bad news is that the username and password are dynamically generated and are only valid for 1 minute. But you can rerun this code and generate new credentials whenever you like. So first, copy the server (SG-mother1-6243.servers.mongodirector.com) and port (27017) into the corresponding boxes on the Server tab of the MongoChef Connection dialog. These shouldn’t change, or at least not often.

Switch to the Authentication tab and make sure that the selected Authentication Mode is “Standard (MONGODB-CR or SCRAM-SHA-1).

Copy the database name (databasename) into the “Authentication DB” box.

That’s good, you’ve got everything set up and ready to connect. Your username and password have probably expired by now, so get fresh ones.

Breathe calmly. Go back to your terminal window and run this again:

meteor mongo --url mysite.meteor.com

This will generate a new set of credentials with a new username and password.

Copy the username (client-d5ba2e88) into the “User name” box in MongoChef.

Copy the password (9cc999cb-9e08-8e63-2c98-ffc3f11a7792) into the Password box.

Click Save.

As soon as the dialog closes, click Connect.

Fingers crossed, MongoChef will now connect to your database, and once it’s connected you can stay in there as long as you like. If it doesn’t work, just try again, generating a new username and password, copying them into the connection in the Connection Dialog.

Note that when you want to reconnect, you’ll again need to go to the Authentication tab and input freshly generated credentials.

Leave a Reply

Your email address will not be published.