小编hel*_*cca的帖子

MongoNetworkError:连接 0 到 localhost:27017 已关闭

我不能让它工作。我已经打开了 mongo 和 mongod,这就是我在 git Bash 或 cmd 中编写“node server.js”时得到的:

Running on server27017
Not connected to database MongoNetworkError: connection 0 to localhost:27017 
closed
Run Code Online (Sandbox Code Playgroud)

这是我的代码。

var express = require('express');
var app = express();
var port = 27017;

//Route
app.get('/', function (req, res) {
    res.send('Hello world!');
});


const mongoose = require('mongoose');
const option = {
    socketTimeoutMS: 30000,
    keepAlive: true,
    reconnectTries: 30000
};

mongoose.connect('mongodb://localhost:27017/database1', option).then(function(){
    //connected successfully
    console.log('Successfully connected to database');
}, function(err) {
    //err handle
    console.log('Not connected to database ' + err); …
Run Code Online (Sandbox Code Playgroud)

mongoose mongodb

6
推荐指数
1
解决办法
7921
查看次数

标签 统计

mongodb ×1

mongoose ×1