Code Monkey home page Code Monkey logo

Comments (3)

NieShiyi avatar NieShiyi commented on June 20, 2024

我也遇到了同样的问题,node版本是18.x。我看到对应的mongodb包的版本是6.x,我升级之后还是不行。感觉是项目中的mongodb版本太老了,已经不支持OP_QUERY command的一些指令了,但是具体怎么解决呢?

from node-elm.

NieShiyi avatar NieShiyi commented on June 20, 2024

我更新了connect-mongo这个库

import express from "express";
import db from "./mongodb/db.js";
import config from "config-lite";
import router from "./routes/index.js";
import cookieParser from "cookie-parser";
import session from "express-session";
import connectMongo from "connect-mongo";
import winston from "winston";
import expressWinston from "express-winston";
import history from "connect-history-api-fallback";
import chalk from "chalk";
// import Statistic from './middlewares/statistic'

const app = express();

app.all("*", (req, res, next) => {
  const { origin, Origin, referer, Referer } = req.headers;
  const allowOrigin = origin || Origin || referer || Referer || "*";
  res.header("Access-Control-Allow-Origin", allowOrigin);
  res.header(
    "Access-Control-Allow-Headers",
    "Content-Type, Authorization, X-Requested-With"
  );
  res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
  res.header("Access-Control-Allow-Credentials", true); //可以带cookies
  res.header("X-Powered-By", "Express");
  if (req.method == "OPTIONS") {
    res.sendStatus(200);
  } else {
    next();
  }
});

// app.use(Statistic.apiRecord)
// const MongoStore = connectMongo(session);
app.use(cookieParser());
app.use(
  session({
    name: config.session.name,
    secret: config.session.secret,
    resave: true,
    saveUninitialized: false,
    cookie: config.session.cookie,
    store: connectMongo.create({
      mongoUrl: config.url,
    }),
  })
);

// app.use(expressWinston.logger({
//     transports: [
//         new (winston.transports.Console)({
//           json: true,
//           colorize: true
//         }),
//         new winston.transports.File({
//           filename: 'logs/success.log'
//         })
//     ]
// }));

router(app);

// app.use(expressWinston.errorLogger({
//     transports: [
//         new winston.transports.Console({
//           json: true,
//           colorize: true
//         }),
//         new winston.transports.File({
//           filename: 'logs/error.log'
//         })
//     ]
// }));

app.use(history());
app.use(express.static("./public"));
app.listen(config.port, () => {
  console.log(chalk.green(`成功监听端口:${config.port}`));
});

可以试试更新以上的库这样后行不。
不行的话。还可以更新这两个库
"mongodb": "^6.6.1",
"mongoose": "^8.3.4" (这个更新后会说findOne已经不知回调了,改成promise)的写法就可以了

我现在可以成功启动了

from node-elm.

Skirt46 avatar Skirt46 commented on June 20, 2024

from node-elm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.