MongoError:服务器ds00000-a.mongolab.com:00000套接字已关闭

时间:2015-12-22 02:06:19

标签: mongodb post mlab

{ [MongoError: server ds00000-a.mongolab.com:00000 sockets closed]
  name: 'MongoError',
  message: 'server ds00000-a.mongolab.com:000000 sockets closed' }

您好,

如何解决此错误?我用mongolabs。连接看起来很好,因为它返回一个ping命令,当我从mongo shell连接它时。但是,当我尝试发布'时,我的节点应用程序会出现以下错误:到数据库。

server.js

var http = require('http').Server(app);
var mongo = require('mongoskin');
var db = mongo.db("mongodb://xxxx:xxxx@ds00000.mongolab.com:0000/col1", {native_parser:true});

app.use(function(req,res,next){
    req.db = db;
    res.header('Access-Control-Allow-Origin', '*');
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
    res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');
    next();
});

 app.post('/',function(req,res){
       data2= { "name":"test",
               "email": "test",
               "number":"test",
               "message":"test"
              };
            db.collection('messages').insert(data2,function(err,result){
                if(err){
                    console.log(err);
                }
                else{

                    console.log('insertion success');
                }

            });

             db.close();
            console.log('Connection with MongoDB is terminated');
    });

谢谢。

0 个答案:

没有答案