After mongodb starts the service, why does post request to exit directly once?

  mongodb, question

I don’t understand why mongodb’s connection goes wrong after writing a login interface. As long as the login request is sent once, its service will exit directly after the request is completed.

When starting the service, connect to the database:

const mongoose = require("mongoose");
 const db = require('../db/config/key').mongoURI;
 //connect db
 mongoose.connect(db,{ useNewUrlParser: true }).then( () => console.log('DB Successful!'  )).catch((err) => console.log(err));

The following is my login interface:

/* * Login
 The * authenticate () method has 3 parameters, the first is name, which is the name of the authentication policy, and the second is options, which is
 */"/login",urlencodedParser,(req,res,next) => {
 const loginUser = {,
 passport.authenticate('local', {
 failureRedirect: '/admin/login',
 failureFlash: true
 })(req, res, next);
 // UserSchema.findOne({
 //   }).then(users => {
 //console.log ('does user exist?'  + users)
 //     if(!  users){
 //       return done(null, false, {message: 'No User Found'});
 //     }
 ////Verify Password
 //, users.password, (err, isMatch) => {
 //       if(err) throw err;
 //       if(isMatch){
 //         res.redirect('/')
 //       } else {
 //         res.redirect('/admin/login')
 //       }
 //     })
 //   })


const UserSchema = require('../models/UserSchema');
 module.exports = function(passport){
 passport.use(new LocalStrategy({usernameField: 'email'}, (email, password, done) => {
 Log ('field obtained:'+email+'/'+ password)
 // Match user
 }).then(users => {
 Log ('does user exist?'  + users)
 if(!  users){
 return done(null, false, {message: 'No User Found'});
 // Match password, users.password, (err, isMatch) => {
 console.log('password   ' + password);
 console.log('user.password' + users.password);
 if(err) throw err;
 console.log('isMatch   ' + isMatch)
 //login successful, return token
 // const rule = {
 //     id: users._id,
 //     admin:'true'
 // };
 // jwt.sign(rule,secretKey,{expiresIn:3600},(err,token) => {
 //   if(err) throw err;
 //   res.json({
 //       sucess:true,
 //       token:"Bearer " + token
 //   });
 // });
 return done(null, users);
 } else {
 return done(null, false, {message: 'Password Incorrect'});

As long as you send a request, you will exit directly, and then there will be such a prompt in the window and it will be broken again.

{ MongoNetworkError: failed to connect to server [localhost:27017] on first connect [MongoNetworkError: connect ECONNREFUSED]
 at Pool.<anonymous> (E:\API\anviz\anviz\web\node_modules\mongodb-core\lib\topologies\server.js:564:11)
 at Pool.emit (events.js:182:13)
 at Connection.<anonymous> (E:\API\anviz\anviz\web\node_modules\mongodb-core\lib\connection\pool.js:317:12)
 at Object.onceWrapper (events.js:273:13)
 at Connection.emit (events.js:182:13)
 at Socket.<anonymous> (E:\API\anviz\anviz\web\node_modules\mongodb-core\lib\connection\connection.js:246:50)
 at Object.onceWrapper (events.js:273:13)
 at Socket.emit (events.js:182:13)
 at emitErrorNT (internal/streams/destroy.js:82:8)
 at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
 at process._tickCallback (internal/process/next_tick.js:63:19)
 name: 'MongoNetworkError',
 errorLabels: [ 'TransientTransactionError' ],
 [Symbol(mongoErrorContextSymbol)]: {} }

I have configured mongodb locally and have added mongodb services in windows.
When the computer is started, the mongodb service is also started. The configuration in the windows startup service is: e: apidbbinmongod.exe-bind _ ip e: apidblogmongodb.log-logappend-dbpath e: apidbdatadb-port27017-service

However, after each service startup, it must be manually knocked again: mongod.exe-dbpath e: apidbdatadb will be started successfully, then this manually started service can only be used once, and the request is directly broken once?

What is the reason?
Thank you very much!

Isn’t this your mistake of connection failure ~

You startedmongodbThe service is right, the key is that I didn’t see your program has connected operation.