Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

启动之后报错 好像是mongodb的问题 #292

Open
lxh666666 opened this issue May 6, 2024 · 3 comments
Open

启动之后报错 好像是mongodb的问题 #292

lxh666666 opened this issue May 6, 2024 · 3 comments

Comments

@lxh666666
Copy link

Unhandled rejection MongoError: Unsupported OP_QUERY command: listIndexes. The client driver may require an upgrade. For more details see https://dochub.mongodb.org/core/legacy-opcode-removal
at Function.MongoError.create (D:\code\node-elm\node_modules\mongodb-core\lib\error.js:31:11)
at queryCallback (D:\code\node-elm\node_modules\mongodb-core\lib\cursor.js:212:36)
at D:\code\node-elm\node_modules\mongodb-core\lib\connection\pool.js:469:18
From previous event:
at MongoStore.setAutoRemoveAsync (D:\code\node-elm\node_modules\connect-mongo\src\index.js:129:40)
at MongoStore.handleNewConnectionAsync (D:\code\node-elm\node_modules\connect-mongo\src\index.js:121:18)
at newConnectionCallback (D:\code\node-elm\node_modules\connect-mongo\src\index.js:79:26)
at connectCallback (D:\code\node-elm\node_modules\mongodb\lib\mongo_client.js:527:5)
at D:\code\node-elm\node_modules\mongodb\lib\mongo_client.js:430:11
at processTicksAndRejections (node:internal/process/task_queues:77:11)

D:\code\node-elm\node_modules\mongoose\node_modules\mongodb-core\lib\error.js:31
err = new MongoError(options.message || options.errmsg || options.$err || "n/a");
^
Error [MongoError]: Unsupported OP_QUERY command: listIndexes. The client driver may require an upgrade. For more details see https://dochub.mongodb.org/core/legacy-opcode-removal
at Function.MongoError.create (D:\code\node-elm\node_modules\mongoose\node_modules\mongodb-core\lib\error.js:31:11)
at queryCallback (D:\code\node-elm\node_modules\mongoose\node_modules\mongodb-core\lib\cursor.js:212:36)
at D:\code\node-elm\node_modules\mongoose\node_modules\mongodb-core\lib\connection\pool.js:469:18
at processTicksAndRejections (node:internal/process/task_queues:77:11) {
ok: 0,
errmsg: 'Unsupported OP_QUERY command: listIndexes. The client driver may require an upgrade. For more details see https://dochub.mongodb.org/core/legacy-opcode-removal',
code: 352,
codeName: 'UnsupportedOpQueryCommand'
}

@NieShiyi
Copy link

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

@NieShiyi
Copy link

我更新了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)的写法就可以了

我现在可以成功启动了

@Skirt46
Copy link

Skirt46 commented May 13, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants