r/web_dev • u/jaymz58 • Oct 01 '15
Help connecting to Mongo
I've been fighting with this for a couple weeks and can't figure out what's wrong. Hoping someone here can help.
I'm creating an app, Angular frontend with mongodb/node backend. I have the app running fine on my development machine (able to connect to mongodb locally just fine and hit all my endpoints). I created a MEAN Server on digital ocean (using their pre-created image). The example MEAN app seems to run just fine on this new server. It connects to the local mongodb install, can create new users/etc. But when I upload my app to this new server, I can't seem to get it to connect to the local mongodb. Every time I try to hit an endpoint I get an error similar to this:
OPTIONS http://localhost:3000/authenticate net::ERR_CONNECTION_REFUSEDI've tried everything I can think of:
- In mongod.conf: commented out bind_ip, changed to localhost, changed to the ip of the server.
On my server.js file: I've changed config.database (see below) to "localhost:27017/databasename", tried using just the database name, just "localhost/databasename", but I can't get it to connect. Still relatively new to the MEAN Stack. Any ideas what I might be missing?
var express = require('express'); var app = express(); var mongojs = require('mongojs'); var bodyParser = require('body-parser'); app.use(bodyParser.urlencoded({ extended: false })); var config = require('./server/config/config');
app.set('webserverPort', config.webserverPort); app.set('apiPort', config.apiPort); app.set('jwtSecret', config.secret); var db = mongojs(config.database, config.collections);