mongodb BSON版本错误的问题,如何找出哪个pkg使用错误

o2rvlv0m  于 2023-04-20  发布在  Go
关注(0)|答案(1)|浏览(143)

在apollo-server v4 graphql中,我尝试使用account-js-server分离用户登录和消息,但不幸的是,我在登录时遇到错误:BSONVersionError:不支持BSON版本,bson类型必须是bson 5.0或更高版本。这是一个问题,mongodb或account-js,想不出解决方案?

{
  "data": {
    "authenticate": null
  },
  "errors": [
    {
      "message": "Unsupported BSON version, bson types must be from bson 5.0 or later",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "authenticate"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "stacktrace": [
          "BSONVersionError: Unsupported BSON version, bson types must be from bson 5.0 or later",
          "    at serializeInto (/app/node_modules/bson/src/parser/serializer.ts:933:15)",
          "    at serializeObject (/app/node_modules/bson/src/parser/serializer.ts:305:20)",
          "    at serializeInto (/app/node_modules/bson/src/parser/serializer.ts:918:17)",
          "    at Object.serialize (/app/node_modules/bson/src/bson.ts:106:30)",
          "    at Msg.serializeBson (/app/node_modules/mongoose/node_modules/mongodb/src/cmap/commands.ts:570:17)",
          "    at Msg.makeDocumentSegment (/app/node_modules/mongoose/node_modules/mongodb/src/cmap/commands.ts:562:33)",
          "    at Msg.toBin (/app/node_modules/mongoose/node_modules/mongodb/src/cmap/commands.ts:548:25)",
          "    at MessageStream.writeCommand (/app/node_modules/mongoose/node_modules/mongodb/src/cmap/message_stream.ts:85:28)",
          "    at write (/app/node_modules/mongoose/node_modules/mongodb/src/cmap/connection.ts:731:26)",
          "    at Connection.command (/app/node_modules/mongoose/node_modules/mongodb/src/cmap/connection.ts:537:7)"
        ]
      }
    }
  ]
}

package.json

{
  "name": "server",
  "private": true,
  "license": "MIT",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "nodemon --exec node --loader ts-node/esm ./src/index.ts",
    "eslint:fix": "eslint --fix"
  },
  "dependencies": {
    "@accounts/graphql-api": "^0.33.2",
    "@accounts/magic-link": "^0.1.1",
    "@accounts/mongo": "^0.34.0",
    "@accounts/password": "^0.32.2",
    "@accounts/server": "^0.33.1",
    "@apollo/server": "^4.6.0",
    "@graphql-modules/core": "^0.7.17",
    "@graphql-toolkit/schema-merging": "^0.10.7",
    "bson": "^5.2.0",
    "dotenv": "^16.0.3",
    "express": "^4.18.2",
    "graphql": "^16.6.0",
    "jsonwebtoken": "^9.0.0",
    "mongo": "^0.1.0",
    "mongoose": "^7.0.3",
    "nodemailer": "^6.9.1"
  },
  "devDependencies": {
    "@graphql-codegen/cli": "^3.3.0",
    "@graphql-codegen/typescript": "^3.0.3",
    "@graphql-codegen/typescript-resolvers": "^3.2.0",
    "@graphql-tools/load-files": "^6.6.1",
    "@graphql-tools/merge": "^8.4.0",
    "@types/express": "^4.17.17",
    "@types/mongodb": "^4.0.7",
    "@types/node": "^18.15.11",
    "@typescript-eslint/eslint-plugin": "^5.57.1",
    "@typescript-eslint/parser": "^5.57.1",
    "eslint": "^8.37.0",
    "eslint-config-prettier": "^8.8.0",
    "eslint-plugin-prettier": "^4.2.1",
    "eslint-plugin-sort-destructure-keys": "^1.5.0",
    "nodemon": "^2.0.22",
    "prettier": "^2.8.7",
    "ts-node": "^10.9.1",
    "ts-node-dev": "^2.0.0",
    "typescript": "^5.0.3"
  }
}

我把mongodb的版本从6降到了5,安装了最新版本的pkg bson,寻找可能的解决方案。
我希望它能让我登录到我的测试GraphQL服务器

y53ybaqx

y53ybaqx1#

似乎类似于this issue。我的解决方法-降级包:

pnpm add mongoose@^6 mongodb@^4

相关问题