`meteor mongo XXX.meteor.com` giving "exception: login failed" - workaround

The problem

New apps deployed via meteor deploy won’t let you connect to their database via meteor mongo. Specifically, this is the error you see:

MongoDB shell version: 2.6.7
connecting to: sg-mother1-6242.servers.mongodirector.com:27017/XXX_meteor_com
2015-12-22T19:15:55.213-0800 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210
exception: login failed

A workaround

In the meanwhile, here’s a workaround:

  1. Install Mongo directly on your machine, not through Meteor. Make sure you’re running the latest version (3.x).
  2. Run the command meteor mongo --url XXX.meteor.com to get the Mongo database to connect to.
  3. Pass that Mongo database directly to the mongo command (not the meteor mongo command). Note that the argument passed to mongo has a different format than what meteor mongo --url returns. Here’s a short script that will automate the conversion process (on Mac or Linux, or Windows with sed installed):
mongo `meteor mongo --url XXX.meteor.com | sed 's/mongodb:\/\//-u /' | sed 's/:/ -p /' | sed 's/@/ /'`

Why is this happening?

New apps deployed with meteor deploy as of about a week ago get a Mongo database from mongodirector.com (this was done to help with the Mongo hosting problems we were hitting). These new Mongo databases are running Mongo 3.0. meteor mongo runs Mongo shell 2.6.7, which can’t connect to Mongo 3.0 instances.

We’ll probably release patch updates to Meteor (potentially to every recent major release). But in the meanwhile the workaround described above should work.

4 Likes

In windows you must use double quotes instead of single quotes. So is:
mongo meteor mongo --url XXX.meteor.com | sed "s/mongodb:\/\//-u /" | sed "s/:/ -p /" | sed "s/@/ /"
Can use echo "(url printed for meteor mongo --url xxx.meteor.com)" | sed "s/mongodb:\/\//-u /" | sed "s/:/ -p /" | sed "s/@/ /"
So now you will have printed the url and you can just enter
mongo (data printed by echo command) and connected!

This workaround is challenging to use: installing mongodb 3 on a 32-bit dev machine is not easy as there are no packages for v3 on 32bit. You have to find the legacy version and install it manually. Go here and choose 32 bit legacy from the version dropdown:

https://www.mongodb.org/downloads#production

Once you’ve done that, you can restore etc as you did previously except that you need to make sure you’re running v3, not your Meteor v2. So preface your ‘mongorestore’ with the path to the new version, for example:

~/mongodb/mongodb-linux-i686-3.2.1/bin/mongorestore -u client-b7c70b07 -h SG-mother1-6243.servers.mongodirector.com:27017 -d mysite_meteor_com -p '3b48b962-c722-9148-6297-2ae6df43fc6f' dump/meteor

This workaround isn’t working for me. I’m still getting the “login failed” exception.

I’m new to Meteor and not sure how to access the deployed website’s MongoDB. I’ve used meteor login to login to meteor before doing the instructions you’ve posted, but to no avail.

Would anyone be able to help? I’ve posted a question on this forum here: Trying to access deployed Meteor website MongoDB Database, getting exception: login failed

Not working for me also… I put in the converted string below in the MongoDB shell, and I get the Syntax Error: missing ; does the string look right? thank you

mongo -u client-f030db79 -p ab0e6e4a-c2d2-1519-dc69-1e34c1f130ac SG-mother1-6242.servers.mongodirector.com:27017/www_myapp_meteor_com
2016-01-20T23:20:48.984-0500 E QUERY [thread1] SyntaxError: missing ; before statement @(shell):1:10

I managed to fix this by reinstalling the latest version of Mongo shell. I believe I had a 2.x (2.6?) version installed originally, and the workaround here only worked for me after I upgraded the Mongo shell to 3.x.

Instead of manually installing Mongodb 3.x, which isn’t very well supported on 32 bit machines, I found it easier to use a GUI such as MongoChef to connect to my database on meteor.com. Note that RoboMongo won’t work because it hasn’t been updated for Mongo shell 3.x.

Here are my notes on how to do this:

http://www.gts-ltd.co.uk/wordpress/2016/01/26/how-to-use-mongochef-to-connect-to-a-meteor-site-hosted-on-meteor-com/

1 Like

wow!! thanks much kwatson… yeah per the GTS Developer Blog post, MongoChef works very well. there’s even a New Connection feature where just type in the URI and it does it everything else.