0

我收到这些错误

MongoError:服务器实例池被破坏

MongoError:拓扑被破坏

如果有人知道是什么导致这个模块出现这些错误以及如何修复它,我会很高兴。.

MongoError:服务器实例池在 Server.update (/home/jnyheim/var/www /node_modules/mongodb-core/lib/topologies/server.js:834:16) 在 Server.update (/home/jnyheim/var/www/node_modules/mongodb/lib/topologies/topology_base.js:326:25) 在updateDocuments (/home/jnyheim/var/www/node_modules/mongodb/lib/operations/collection_ops.js:1344:19) 在/home/jnyheim/var/www/node_modules/mongodb/lib/utils.js:437:24在 Collection.update (/home/jnyheim/var/www/node_modules/mongodb/lib 的 executeOperation (/home/jnyheim/var/www/node_modules/mongodb/lib/utils.js:432:10) /collection.js:829:10) 在 withCallback.collectionReady.then。集合 (/home/jnyheim/var/www/node_modules/connect-mongo/src/index.js:244:48) at process._tickCallback (internal/process/next_tick.js:188:7) MongoError: 拓扑被破坏在 nextFunction (/home/jnyheim/var/www/node_modules/mongodb-core/lib/cursor.js:603:27) 在 Cursor.next (/home/jnyheim/var/www/node_modules/mongodb-core/lib/ cursor.js:824:3) 在 Cursor._next (/home/jnyheim/var/www/node_modules/mongodb/lib/cursor.js:211:36) 在 nextObject (/home/jnyheim/var/www/node_modules/ mongodb/lib/operations/cursor_ops.js:186:10) 在下一个 (/home/jnyheim/var/www/node_modules/mongodb/lib/operations/cursor_ops.js:165:3) 在 executeOperation (/home/jnyheim/ var/www/node_modules/mongodb/lib/utils.js:420:24) 在 Cursor.next (/home/jnyheim/var/www/node_modules/mongodb/lib/cursor.js:253:10) 在 findOne (/home/jnyheim/var/www/node_modules/mongodb/lib/operations/collection_ops.js:542:10) 在 /home/jnyheim/var/www/node_modules/mongodb/lib/utils.js:在 Collection.findOne (/home/jnyheim/var/www/node_modules/ mongodb/lib/collection.js:1021:10) 在 withCallback.collectionReady.then.collection (/home/jnyheim/var/www/node_modules/connect-mongo/src/index.js:192:46) 在findOne (/home/jnyheim/var/www/node_modules/mongodb/lib/collection.js:1021:10) 在 withCallback.collectionReady.then.collection (/home/jnyheim/var/www/node_modules/connect-mongo/src /index.js:192:46) 在findOne (/home/jnyheim/var/www/node_modules/mongodb/lib/collection.js:1021:10) 在 withCallback.collectionReady.then.collection (/home/jnyheim/var/www/node_modules/connect-mongo/src /index.js:192:46) 在

我发现它是由这个 const MongoStore = require('connect-mongo')(session); 模块在执行时 引起的

商店:新的 MongoStore({mongooseConnection:mongoose.connection})

app.use(session({
    secret: "mylittle34secret",
    cookie: { maxAge: (1 * 60 * 60 * 1000) },
    saveUninitialized: false,
    resave: false,
    proxy: true,
    store: new MongoStore({mongooseConnection: mongoose.connection}),
}));

完整代码:

'use strict'

// Dependencies
const expressValidator = require('express-validator');
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const passport = require('passport');
const mongoose = require('mongoose');
const express = require('express');
const session = require('express-session'); 
const MongoStore = require('connect-mongo')(session);
const exphbs = require('express-handlebars');
const paypal = require('paypal-rest-sdk');
const flash = require('connect-flash');
const path = require('path');


mongoose.connect('mongodb://localhost:27017/app', {useNewUrlParser: true, socketTimeoutMS: 0, keepAlive: true, reconnectTries: 30}, (err, db)=>{
if(err){
    console.log('## INCOMMING MONGO ERROR ##' + err + '## MONGO ERROR END ##');
    throw err;
}else{
    console.log("-->  succesfully connected to Database!");
};

//db.once('')
});




const paypal_config = require('./lib/helpers/paypal_configuration.json');

paypal.configure(paypal_config);


const app = express()

// Root Routes
const _shop = require('./route/shop');
const _index = require('./route/index');
const _about = require('./route/about');
const _session = require('./route/session');
const _projects = require('./route/projects');


// View Engine
app.engine('.hbs', exphbs({
extname: '.hbs',
defaultLayout:'layout',
layoutsDir: __dirname + '/views/layouts/'
}));

app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'hbs');

// BodyParser Middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());

// Set Static Folder | Public Folder
app.use(express.static(path.join(__dirname, 'public'))); 

// Express Session
app.use(session({
secret: "mylittle34secret",
cookie: { maxAge: (1 * 60 * 60 * 1000) },
saveUninitialized: false,
resave: false,
proxy: true,
store: new MongoStore({mongooseConnection: mongoose.connection}),

}));

// Passport init
app.use(passport.initialize());
app.use(passport.session());

// Express Body Validator
app.use(expressValidator({
errorFormatter: function(param, msg, value) {
    var namespace = param.split('.')
    , root    = namespace.shift()
    , formParam = root;

  while(namespace.length) {
    formParam += '[' + namespace.shift() + ']';
  }
  return {
    param : formParam,
    msg   : msg,
    value : value
  };
}
}));

// Connect Flash
app.use(flash());

// Vars for HTML doc   
app.use((req, res, next)=>{
res.locals.success_msg = req.flash('success_msg');
res.locals.warning_msg = req.flash('warning_msg');
res.locals.error_msg = req.flash('error_msg');
res.locals.info_msg = req.flash('info_msg');
res.locals.error = req.flash('error');
res.locals.user = req.user || null;
res.locals.session = req.session;
next();
});

// root/routes
app.use('/', _index);                // x/
app.use('/shop', _shop);             // x/shop
app.use('/about', _about);           // x/about  
app.use('/session', _session);       // x/session
app.use('/projects', _projects);     // x/projects

// Server
app.set('port', (process.env.PORT || 80));

app.listen(app.get('port'), ()=>{
console.log('-->  HTTP Server started on port %s', app.get('port'));
});

<3

4

0 回答 0