Changes need to run mongoose on server instead of localhost? - node.js

What are the changes I need to run my app on server instead of localhost

mongoose.connect('mongodb://mongoServerIP/dbName)
Since you are running your mongo in your local, you are using localhost. I am not familiar with heroku server, but in general case, you first need to make sure mongo db is running on your heroku server and than you need to put that IP instead of localhost in the above command.
Please refer http://mongoosejs.com/docs/connections.html in case you need login credentials to access the server or any other reference.

Related

Connecting to a mongoDB with a TCP prefix on a NodeJS application

I created a NodeJS app that connects with a MongoDB and it seems to work locally.
Now, after hosting the NodeJS application on a remote machine, I am trying to connect to a mongoDB that was already created on that machine. When I print out some of the environment variables, the only one I see of relevance seems to be :
MONGODB_PORT: 'tcp://172.30.204.90:27017',
I tried connecting like I usually do with
mongoose.connect('mongodb://localhost:27017/metadata/')
and replacing it with mongoose.connect('tcp://172.30.204.90:27017/metadata') but I get an error that says my URI needs to start with 'mongodb'.
So I tried replacing it with mongoose.connect('mongodb://172.30.204.90:27017/metadata') and it no longer throws any error. But on the MongoDB side I don't see any new connections happening and my app does not start up on the machine. What should I be putting in the URI?
Your URI should indeed start with mongodb:
mongoose.connect('mongodb://username:password#host:port/database?options...');
See this page for more information: https://docs.mongodb.com/manual/reference/connection-string/
Did you try to connect to the database from cli? Or Telnet to see that connection isn't blocked.

MongoLab DB is not responding when using with localhost

I have an Heroku web applicaiton based on MongoLab MongoDB.
Accessing the site via heroku production site works and I see the site is alive.
My development environment is configured to work with the production DB.When I try to connect I get on:
mongoose.connection.on('error', function(err) {
...
});
And err.message = "connect ETIMEDOUT 54.159.67.179:61188"
How should I continue?
If you click through the resources section of the heroku dashboard and then open your mlab resource it should take you to the mlab home.
The first bit of information should show you how to connect to your database either though the mongo shell or using the standard URI. If you have mongo installed locally can you connect to the remote database this way? If not then it points to network issues. Are you accessing this from behind a corporate proxy? Mongo by default uses port 27017 which isn't open on most corporate proxies. If this is the case then I would speak to your network administrator. I know that at my company we aren't allowed to use this port, but then we don't use cloud infrastructure (yet). Good luck!
I faced the same issue. Solution for me ended up that the environment variable (stored in a .env file in my app) had an old "configvar" (Heroku terminology) and:
go to the desired app Settings tab in Heroku
click the Reveal ConfigVars button
copy the MONGODB_URI value
paste the URI into the .env file (or wherever you store)
That was it, back in business.

database settings in reactioncommerce

I installed reactioncommerce and I would like to access the database settings to check the name that the installation created in my mongodb server. I checked the information on the website but I cannot find any details about it.
in mongodb: when I use "show dbs" in mongo I cannot see any new db in my server. on the other hand, the demo application is running on port localhost:3000.
any guidance appreciated.
well it seems the mongodb for meteor always runs at one port above the meteor port. So by default the db is running at 3001. While you can have Meteor running you can also run meteor mongo and get a db console that way.

How to access mongodb spawned by meteor app on a remote server?

I have a meteor application with mongodb running on one of my systems. I want another application running on a different system to be able to access the mongodb that is spawned by my meteor application.
How can I accomplish this because by default the mongodb bind ip is localhost, so it's not accessible from outside.
Not recommended but you can disable the restriction of MongoDB that can be accessed only via localhost.
See: http://www.mkyong.com/mongodb/mongodb-allow-remote-access/
if your service is on the same server, then use the localhost address:
Meteor tends to expose the mongodb at its adress +1
(if meteor is on port 3000, mongodb is on port 3001)
then your service can access it at localhost:3001
If you want to access from another server, then you need to change the mongodb config to expose the port to the outside (probably also setup some firewall rules to only give access to your other server etc...)
and then use the suggested above
MONGO_URL=mongodb://hostname:port
ideally deploy your mongodb securely somewhere and plug Meteor an any other app needing it to it via the connection string.

keep separate the local database for local dev and nodejutsu database URL for nodejitsu app?

When I'm developing on my local box I use mongodb://localhost/Data as my connection string when connecting to mongoDB that's running locally.
But then when I upload/update my local app to nodejitsu I have to change the url to the one provided by nodejitsu mongodb://nodejitsu_XXX:xyxyxyxy.mongolab.com:29950/nodejitsu_XXX_nodejitsudb12121212
How do I switch between my localhost mongoDB connection URL and the one provided by Nodejitsu? I don't wanna keep changing it and committing the changes everytime I want to test out my local changes in the cloud...
I use nconf https://github.com/flatiron/nconf , you can easily change between diferent configurations

Resources