本文介绍了无法通过浏览器访问mongodb - 看起来您正在本地驱动程序端口上通过HTTP访问MongoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打开终端并输入以下命令

  sudo mongod 
pre>

然后输出

  [initandlisten]等待连接港口27017 

我打开另一个终端并输入

  sudo mongo 

打开mongo shell并提示mongo命令,但是当我去本地/ 27017我收到以下消息:

 看起来你正在尝试访问MongoDB通过本地驱动程序端口上的HTTP。 

我使用express创建了一个简单的nodejs应用程序,当我 POST 数据似乎mongodb挂断了。这是我在终端中收到的消息,其中我启动我的快速应用程序,该页面从不发布数据。所以我相信这个问题在于mongo,但我无法理解。

  POST / info 200 120002ms 

这是我的快递代码

  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('exports.submit 1');
return function(req,res,next){
console.log('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('/')
});
}
};

模型

  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);
...


解决方案

你可以开始mongodb与

  mongod --httpinterface 

并访问

  http:// localhost:28017 

自2.6版以来,MongoDB默认禁用HTTP界面。




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);
...
解决方案

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.

See http://docs.mongodb.org/manual/reference/program/mongod/#cmdoption--httpinterface

这篇关于无法通过浏览器访问mongodb - 看起来您正在本地驱动程序端口上通过HTTP访问MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 19:25