Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot access mongodb through browser - It looks like you are trying to access MongoDB over HTTP on the native driver port

I open terminal and enter the following commands

sudo mongod 

which then outputs

[initandlisten] waiting for connections on port 27017 

I open another terminal and enter

sudo mongo 

which open the mongo shell and prompts for mongo commands, but when I go to localhost/27017 I receive the following message:

It looks like you are trying to access MongoDB over HTTP on the native driver port. 

I created a simple nodejs application using express and when I POST data it seems the mongodb gets hung up. This is the message which I receive in the terminal in which I start my express application and the page never posts the data. So I believe the problem lies within mongo but I cannot figure it out.

POST /info 200 120002ms 

Here is my express code

var Info = require('../models/info'); var path = require('path'); var fs = require('fs'); var join = path.join;  exports.form = function(req,res){      res.render('info', {         myName: 'Michael'     }); };  exports.submit = function(){ console.log('Within exports.submit 1');     return function(req,res,next){         console.log('Within exports.submit 2 ');         var firstName = req.name.first;         var lastName = req.name.last;         Info.create({             firstName: firstName,             lastName: lastName         },function(err){             if(err) return next(err);              res.redirect('/')         });     } }; 

Model

var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/info');  var schema = new mongoose.Schema({     firstName: String,     lastName: String });  module.exports = mongoose.model('info',schema); 

app.js

... app.get('/info',info.form); app.post('/info',info.submit); ... 
like image 790
Michael Avatar asked May 03 '14 16:05

Michael


People also ask

How do I access MongoDB HTTP?

HTTP Console MongoDB provides a simple http interface listing information of interest to administrators. This interface may be accessed at the port with numeric value 1000 more than the configured mongod port. The default port for the http interface is 28017.

How do I access MongoDB from browser?

By default, MongoDB starts at port 27017. But you can access it in a web browser not at that port, rather, at a port number 1000 more than the port at which MongoDB is started. So if you point your browser to http://localhost:28017, you can see MongoDB web interface.

How do I access MongoDB on localhost?

To connect to your local MongoDB, you set Hostname to localhost and Port to 27017 . These values are the default for all local MongoDB connections (unless you changed them). Press connect, and you should see the databases in your local MongoDB.


2 Answers

Before Mongo 3.6:

You may start mongodb with

mongod --httpinterface 

And access it on

http://localhost:28017 

Since version 2.6: MongoDB disables the HTTP interface by default.

Update

HTTP Interface and REST API

MongoDB 3.6 removes the deprecated HTTP interface and REST API to MongoDB.

See Mongo http interface and rest api

like image 78
David Avatar answered Oct 08 '22 11:10

David


MongoDB has a simple web based administrative port at 28017 by default.

There is no HTTP access at the default port of 27017 (which is what the error message is trying to suggest). The default port is used for native driver access, not HTTP traffic.

To access MongoDB, you'll need to use a driver like the MongoDB native driver for NodeJS. You won't "POST" to MongoDB directly (but you might create a RESTful API using express which uses the native drivers). Instead, you'll use a wrapper library that makes accessing MongoDB convenient. You might also consider using Mongoose (which uses the native driver) which adds an ORM-like model for MongoDB in NodeJS.

If you can't get to the web interface, it may be disabled. Normally, I wouldn't expect that you'd need it for doing development unless you're checking logs and such.

like image 31
WiredPrairie Avatar answered Oct 08 '22 13:10

WiredPrairie