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

huangapple go评论100阅读模式
英文:

Mongoose buffering timed out when model is in a referenced project

问题

The project:

我创建了一个ShoppingCard项目来测试TypeScript引用。

The problem:

当模型直接包含在主项目中时,MongoDB连接成功工作。

在http://localhost:8080/api-docs/上进行了测试。

当我将模型移动到引用的项目中时,出现以下错误:

MongooseError: Operation amounttypes.find() buffering timed out after 10000ms

在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不起作用。

英文:

The project:

I made a ShoppingCard project for testing typescript references.

The problem:

When models directly included in main project, MongoDB connection successfully works.

https://github.com/pzoli/shoppingcard-api

Tested in http://localhost:8080/api-docs/

When I move models out to referenced project I get folowing error:

MongooseError: Operation amounttypes.find() buffering timed out after 10000ms

https://github.com/pzoli/shoppingcard-api/tree/ref-models

https://github.com/pzoli/shoppingcard-models

The tsconfig.json in shoppingcard-api is:

  1. {
  2. "compilerOptions": {
  3. "target": "es6",
  4. "module": "commonjs",
  5. "outDir": "./build",
  6. "strict": true,
  7. "esModuleInterop": true,
  8. "experimentalDecorators": true,
  9. "emitDecoratorMetadata": true
  10. },
  11. "references": [{ "path": "../shoppingcard-models" }],
  12. }

The tsconfig.json in shoppingcard-models is:

  1. {
  2. "compilerOptions": {
  3. "sourceMap": true,
  4. "target": "esnext",
  5. "module": "CommonJS",
  6. "outDir": "./dist",
  7. "baseUrl": "./src",
  8. "alwaysStrict": true,
  9. "noImplicitAny": true,
  10. "importHelpers": true,
  11. "experimentalDecorators": true,
  12. "forceConsistentCasingInFileNames": true,
  13. "esModuleInterop": true,
  14. "emitDecoratorMetadata": true,
  15. "strictPropertyInitialization": false,
  16. "skipLibCheck": true,
  17. "moduleResolution": "node",
  18. "allowSyntheticDefaultImports": true,
  19. "types": [
  20. "node",
  21. ],
  22. "rootDir": "./src",
  23. "typeRoots": [
  24. "node_modules/@types"
  25. ],
  26. "composite": true
  27. },
  28. "include": [
  29. "src/**/*.ts"
  30. ],
  31. "exclude": [
  32. "node_modules",
  33. "dist"
  34. ]
  35. }

The package.json in shoppingcard-api is:

  1. {
  2. "name": "quizserver",
  3. "version": "1.0.0",
  4. "description": "",
  5. "main": "app.js",
  6. "scripts": {
  7. "start": "node build/app.js",
  8. "build": "tsc",
  9. "dev": "nodemon"
  10. },
  11. "nodemonConfig": {
  12. "watch": [
  13. "src"
  14. ],
  15. "ext": "ts",
  16. "exec": "ts-node src/app.ts"
  17. },
  18. "keywords": [],
  19. "author": "",
  20. "license": "ISC",
  21. "dependencies": {
  22. "dotenv": "^16.0.3",
  23. "express": "^4.18.2",
  24. "joi": "^17.9.1",
  25. "mongoose": "^7.0.4",
  26. "swagger-ui-express": "^4.6.2",
  27. "typescript": "^5.0.4",
  28. "yaml": "^2.2.1"
  29. },
  30. "devDependencies": {
  31. "@types/express": "^4.17.17",
  32. "@types/joi": "^17.2.3",
  33. "@types/node": "^18.15.12",
  34. "@types/swagger-ui-express": "^4.1.3",
  35. "nodemon": "^2.0.22",
  36. "ts-node": "^10.9.1"
  37. }
  38. }

The package.json in shoppingcard-models is:

  1. {
  2. "name": "backend-models",
  3. "version": "1.0.0",
  4. "description": "",
  5. "scripts": {
  6. "test": "echo \"Error: no test specified\" && exit 1",
  7. "build": "tsc"
  8. },
  9. "author": "",
  10. "license": "ISC",
  11. "dependencies": {
  12. "joi": "^17.9.2",
  13. "mongoose": "^7.2.2",
  14. "tslib": "^2.5.3"
  15. }
  16. }

Please help find why Mongoose not work.

答案1

得分: 0

我在mongoose的GitHub问题跟踪器中得到以下答案:

> 我猜你的独立项目有一个不同的Mongoose模块副本,所以导出model()导出的是连接到错误的Mongoose模块副本的模型。
>
> 让shoppingcard-models导出模式而不是模型,然后在你的主项目中调用model()。

英文:

I get following answer in mongoose github issue tracker:

> I'm guessing your separate project has a different copy of the
> Mongoose module, so exporting model() exports a model that's connected
> to the wrong copy of the Mongoose module.
>
> Make shoppingcard-models export schemas instead of models, and instead
> call model() in your main project.

huangapple
  • 本文由 发表于 2023年6月6日 16:56:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76412971.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定