Cannot access mongoDB after "meteor deploy myapp.com" - mongodb

I deployed my app using meteor deploy myapp.com, and directed my DNS to myapp.meteor.com.
The app is now available at myapp.com, and I have no problem running it. It's the correct version that was deployed to "myapp.com" and not the older "myapp.meteor.com" version.
But I cannot access mongodb for this deployed version.
When I run meteor mongo myapp.com, I get this at the terminal:
MongoDB shell version: 2.6.7
connecting to: sg-mother1-6242.servers.mongodirector.com:27017/myapp_com
2016-03-10T16:46:18.659-0800 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210
exception: login failed
I am also getting the same error when I run meteor mongo myapp.meteor.com:
MongoDB shell version: 2.6.7
connecting to: someserver.servers.mongodirector.com:27017/myapp_meteor_com
2016-03-10T16:45:54.367-0800 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210
exception: login failed
When I do meteor mongo --url myapp.com, I do get a URL back of the form:
mongodb://<user>:<password>#<some-servername>.servers.mongodirector.com:27017/myapp_com
But I cannot connect to this URL using Robomongo. I get an error:
Cannot connect to MongoDB (<some-servername>.servers.mongodirector.com:27017),
error: Unable to connect to MongoDB
What am I doing wrong? How do I connect to the mongoDB for the app I deployed on my custom domain? Preferably using some GUI tool such as Robomongo?

What I understand, is that the local install of Meteor uses Mongodb 2.6 and newly deployed Meteor sites use Mongodb 3.0
When you call meteor mongo myapp.meteor.com you are using meteor's locally installed version of mongo (version 2.6) but you are trying to access the deployed mongodb (version 3.0). This results in the authentication error you are getting.
This link describes a workaround that worked for me. I had to tweak it a little, but this is what I did:
Install or update your local version of Mongo (not through Meteor).
Run the command meteor mongo --url myapp.meteor.com to get the MONGO_URL. As you already mentioned, you'll get something like
mongodb://<user>:<password>#<some-servername>.servers.mongodirector.com:27017/myapp_com
Connect to the MONGO_URL using your updated non-meteor version of mongo by running
mongo mongodb://<user>:<password>#<some-servername>.servers.mongodirector.com:27017/myapp_com
You should now be in the mongoshell, connected to your deployed mongodb. You should see something like this RS-mother1-0:PRIMARY> in your mongo shell. You still need to switch to your app's DB though. So call use myapp_com from the shell.
You should now be able to view collections and run mongo commands on your deployed meteor mongodb.
I'm not sure why you can't connect to Robomongo using the username and password meteor generates for you in the MONGO_URL. I suspect it's because it might expire. If you still want to connect using Robomongo, I'd recommend creating a user on the database now that you are logged in. And then later on, using that user to log into Robomongo.
Creating the user in the mongo shell:
db.createUser({ "user" : "my_user", "pwd": "my_password", "roles" : ["readWrite"]})
New MONGO_URL:
mongodb://my_user:my_password#<some-servername>.servers.mongodirector.com:27017/myapp_com

Related

MongoDB not working on deployed Meteor project

I've been working on a project with some friends using MongoDB and Meteor. It was working fine until we deployed it, we noticed the Mongo DB was not connecting to the Meteor app.
We are using:
Azure's Virtual Machine server
Meteor for development
Mongo for our database (Hosted in Azure's Document DB, different location from the Meteor's Azure VM)
Meteor up (mup) for deployment
We did notice that when we run the project locally with meteor, we need to specify the MONGO_URL on the same command (MONGO_URL="MongoDB connection string" meteor) if not, it doesn't connect to the db. This may be happening on the website, although we have specified the mongo url in the mup as follows:
env: {
ROOT_URL: 'IP',
MONGO_URL: '<URL>'
},
We have checked everything and not sure how to proceed, any feedback would help.
EDIT: Specify server locations

How to check meteor production database [duplicate]

It seems the answer in this thread (Accessing Meteor production database) does not work anymore when you want to access a meteor production database in 2016. I want to access a meteor production database blah.meteor.com using
meteor mongo blah.meteor.com
instead what I get is:
connecting to: sg-mother1-6243.servers.mongodirector.com:27017/blah_meteor_com
2016-01-18T15:21:49.884+0200 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210
exception: login failed
Then I tried
meteor mongo --url blah.meteor.com
I get username cursor. I enter my meteor site username and press enter and then get password cursor. I enter password for the above username and press enter. I get presented with the following url:
mongodb://client-2ee8c14d:c1546ca8-4e7e-5883-0214-150b309fb4fb#SG-mother1-6242.servers.mongodirector.com:27017/blah_meteor_com
Then every time I re-enter
meteor mongo --url blah.meteor.com
I am assumed to have logged on already, and I just get presented with a similar url to the one I was presented with just above.
I read the "meteor mongo command" documentation by entering:
meteor mongo --help
In the documentation I read the following line:
Instead of opening a shell, specifying --url (-U) will return a URL
suitable for an external program to connect to the database. For remote
databases on deployed applications, the URL is valid for one minute.
For the meaning, I went back to the thread (stackoverflow.com/questions/11801278/accessing-meteor-production-database) I mentioned in the beggining and read:
"So what it's saying is, the url provided by running the command with the --url option is for connecting to the database by some external application, i.e. other than meteor."
I don't know what other application can help me connect to meteor production database other than what I used to do in 2015, which is:
meteor mongo blah.meteor.com
I read somewhere that I can use the mongo shell intead but I don't know how to open it and I don't know the mongo installation directory when it is installed with meteor. I am using linux (fedora) OS.
How do I access meteor production database in 2016? Are there upgrades that happened that make me not to be able to access meteor production database as easily as I did in 2015?
You are trying to connect to a database version 3.0 while your meteor mongo command still use the version 2.6.7 of mongo
Try this workaround :
Install Mongo version (3.x) directly on your machine.
Then run this command (should work on osx, linux and windows when sed is installed):
mongo `meteor mongo --url XXX.meteor.com | sed 's/mongodb:\/\//-u /' | sed 's/:/ -p /' | sed 's/#/ /'`
Source: https://forums.meteor.com/t/meteor-mongo-xxx-meteor-com-giving-exception-login-failed-workaround/15289
Since Meteor stopped supporting the use of .meteor domains and every developer needs to get his hosting by himself, I found a way accessing the remote's database by using mup or mupx. I wrote it in this post: https://stackoverflow.com/a/37439315/2908071
I hope this will help future people.

What is the mongodb server url for meteor

I am using PhpStorm editor with mongoDB plugin, I was wondering what should be the mongodb server url,so I could monitor my mongoDB's activities directly from PhpStorm
It depends if you set MONGO_URL. If you run meteor locally with out setting MONGO_URL try
mongo localhost:3001/meteor
If you have deployed your app to meteor.com try
meteor mongo yourapp.meteor.com --url
This will return the MONGO_URLso that you can monitor/backup/restore your DB. Eg
mongodb://client-lots-of-numers#production-db-a1.meteor.io:27017/yourapp_meteor_com
When running MongoDB using the meteor command line you can access the database at localhost:3001. The database name is meteor and there is no need for credentials.

Connect to Mongo from Meteor

I have Windows PC running two ubuntu virtual machines. One has Meteor installed (app server), to other has Mongo installed (the purpose of this is to use Mongo away from the app server so that it will scale later on). Problem is that I cannot connect to Mongo instance from Meteor!
I can connect to the mongo instance from the the app server when using the line below on the command line and can retrieve data from the collection:
mongo 192.168.56.112/mydb -u myusername -pmypassword
I can also start my meteor app. using:
MONGO_URL="mongodb://myusername:mypassword#192.168.56.112/mydb" meteor
However, when doing the latter, I get an error "ReferenceError: mycollection is not defined".
Can anyone help my to identify why meteor won't connect to mongo?
As per Evgeny's suggestion, the answer is to define a variable for my collection:
Chatrooms = new Meteor.Collection("chatrooms");

How is MongoDb installed by Meteor?

I'm new to both Meteor.js and MongoDB and after installing Meteor in the official way described I wonder how to connect to my MongoDB.
MongoDB was installed by Meteor during the installation and everything works fine but now I would like to have a look into it with another tool (like RazorSQL) to see what's in there.
But the standard connection parameters (localhost:27017) doesn't work, what can I do? Login? Password?
Update: February 2014 - Meteor 0.7.1 - The meteor port has been shifted to 3001 instead of 3002. So instead of adding two to the port meteor runs on, you add 1 instead.
MongoDB's database is installed in the meteor package containing your files in a hidden folder called .meteor. To access it from a remote tool simply add 2 to whatever your web server port is while meteor is running. It will be stored in the meteor database
e.g
http://localhost:3000 would have its mongodb server running at mongodb://localhost:3002/meteor there is no username/password on this instance if you ran it with meteor or meteor run
To get the Meteor Mongo url and port, first run your Meteor app using meteor run then run meteor mongo in a different terminal tab. You should see an output like this
[meteor-app] meteor mongo
MongoDB shell version: 2.6.7
connecting to: 127.0.0.1:3001/meteor
this means that your Meteor Mongo is running at 127.0.0.1:3001.
If you are running your Meteor app with meteor run then you neither need username/password nor authentication configuration just make sure that you set your default database name as meteor