mongodb 当模型位于引用的项目中时,Mongoose缓冲超时

z4iuyo4d  于 2023-06-29  发布在  Go
关注(0)|答案(1)|浏览(97)

该项目:
我做了一个ShoppingCard项目来测试typescript引用。
问题:
当模型直接包含在主项目中时,MongoDB连接成功工作。
https://github.com/pzoli/shoppingcard-api
测试在http://localhost:8080/api-docs/
当我将模型移到引用的项目时,我得到以下错误:
MongooseError:操作amounttypes.find()缓冲在10000 ms后超时
https://github.com/pzoli/shoppingcard-api/tree/ref-models
https://github.com/pzoli/shoppingcard-models
shoppingcard-api中的tsconfig.json为:

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "outDir": "./build",
    "strict": true,
    "esModuleInterop": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  },
  "references": [{ "path": "../shoppingcard-models" }],
}

shoppingcard-models中的tsconfig.json是:

{
  "compilerOptions": {
    "sourceMap": true,
    "target": "esnext",
    "module": "CommonJS",
    "outDir": "./dist",
    "baseUrl": "./src",
    "alwaysStrict": true,
    "noImplicitAny": true,
    "importHelpers": true,
    "experimentalDecorators": true,
    "forceConsistentCasingInFileNames": true,
    "esModuleInterop": true,
    "emitDecoratorMetadata": true,
    "strictPropertyInitialization": false,
    "skipLibCheck": true,
    "moduleResolution": "node",
    "allowSyntheticDefaultImports": true,
    "types": [
      "node",
    ],
    "rootDir": "./src",
    "typeRoots": [
      "node_modules/@types"
    ],
    "composite": true
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "dist"
  ]
}

shoppingcard-api中的package.json为:

{
  "name": "quizserver",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "start": "node build/app.js",
    "build": "tsc",
    "dev": "nodemon"
  },
  "nodemonConfig": {
    "watch": [
      "src"
    ],
    "ext": "ts",
    "exec": "ts-node src/app.ts"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "dotenv": "^16.0.3",
    "express": "^4.18.2",
    "joi": "^17.9.1",
    "mongoose": "^7.0.4",
    "swagger-ui-express": "^4.6.2",
    "typescript": "^5.0.4",
    "yaml": "^2.2.1"
  },
  "devDependencies": {
    "@types/express": "^4.17.17",
    "@types/joi": "^17.2.3",
    "@types/node": "^18.15.12",
    "@types/swagger-ui-express": "^4.1.3",
    "nodemon": "^2.0.22",
    "ts-node": "^10.9.1"
  }
}

shoppingcard-models中的package.json是:

{
  "name": "backend-models",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "tsc"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "joi": "^17.9.2",
    "mongoose": "^7.2.2",
    "tslib": "^2.5.3"
  }
}

请帮助找出为什么Mongoose不工作。

mwg9r5ms

mwg9r5ms1#

我在mongoose github issue tracker中得到了以下答案:
我猜您的独立项目有Mongoose模块的不同副本,因此exporting model()导出的模型连接到错误的Mongoose模块副本。
使shoppingcard-models导出模式而不是模型,并在主项目中调用model()。

相关问题