gpt4 book ai didi

javascript - Sails.js "Could not tear down ORM hook"错误与 sails-mongo

转载 作者:行者123 更新时间:2023-11-29 20:52:30 31 4
gpt4 key购买 nike

我最近在笔记本电脑上将 Sails 从 0.12 更新到 1.0.2,并开始了一个新项目。我正在尝试使用 sails-mongo 连接到 MongoDB 数据库,但出现以下错误:

my-app_1  | error: A hook (`orm`) failed to load!
my-app_1 | error: Could not tear down the ORM hook. Error details: Error: Consistency violation: Attempting to tear down a datastore (`default`) which is not currently registered with this adapter. This is usually due to a race condition in userland code (e.g. attempting to tear down the same ORM instance more than once), or it could be due to a bug in this adapter. (If you get stumped, reach out at http://sailsjs.com/support.)
my-app_1 | at Object.teardown (/usr/src/app/node_modules/sails-mongo/lib/index.js:390:19)
my-app_1 | at /usr/src/app/node_modules/waterline/lib/waterline.js:758:27
my-app_1 | at /usr/src/app/node_modules/async/dist/async.js:3047:20
my-app_1 | at eachOfArrayLike (/usr/src/app/node_modules/async/dist/async.js:1002:13)
my-app_1 | at eachOf (/usr/src/app/node_modules/async/dist/async.js:1052:9)
my-app_1 | at Object.eachLimit (/usr/src/app/node_modules/async/dist/async.js:3111:7)
my-app_1 | at Object.teardown (/usr/src/app/node_modules/waterline/lib/waterline.js:742:11)
my-app_1 | at Hook.teardown (/usr/src/app/node_modules/sails-hook-orm/index.js:246:30)
my-app_1 | at Sails.wrapper (/usr/src/app/node_modules/@sailshq/lodash/lib/index.js:3275:19)
my-app_1 | at Object.onceWrapper (events.js:313:30)
my-app_1 | at emitNone (events.js:106:13)
my-app_1 | at Sails.emit (events.js:208:7)
my-app_1 | at Sails.emitter.emit (/usr/src/app/node_modules/sails/lib/app/private/after.js:56:26)
my-app_1 | at /usr/src/app/node_modules/sails/lib/app/lower.js:67:11
my-app_1 | at beforeShutdown (/usr/src/app/node_modules/sails/lib/app/lower.js:45:12)
my-app_1 | at Sails.lower (/usr/src/app/node_modules/sails/lib/app/lower.js:49:3)
my-app_1 | error: Failed to lift app: Error: Consistency violation: Unexpected error creating db connection manager:
my-app_1 | ```
my-app_1 | ImplementationError: Internal error occurred while running `createManager`. Got non-Error: { MongoError: failed to connect to server [mongodb:27017] on first connect [MongoError: getaddrinfo ENOTFOUND mongodb mongodb:27017]
my-app_1 | at Pool.<anonymous> (/usr/src/app/node_modules/mongodb-core/lib/topologies/server.js:327:35)
my-app_1 | at emitOne (events.js:116:13)
my-app_1 | at Pool.emit (events.js:211:7)
my-app_1 | at Connection.<anonymous> (/usr/src/app/node_modules/mongodb-core/lib/connection/pool.js:274:12)
my-app_1 | at Object.onceWrapper (events.js:317:30)
my-app_1 | at emitTwo (events.js:126:13)
my-app_1 | at Connection.emit (events.js:214:7)
my-app_1 | at Socket.<anonymous> (/usr/src/app/node_modules/mongodb-core/lib/connection/connection.js:177:49)
my-app_1 | at Object.onceWrapper (events.js:315:30)
my-app_1 | at emitOne (events.js:116:13)
my-app_1 | at Socket.emit (events.js:211:7)
my-app_1 | at emitErrorNT (internal/streams/destroy.js:64:8)
my-app_1 | at _combinedTickCallback (internal/process/next_tick.js:138:11)
my-app_1 | at process._tickCallback (internal/process/next_tick.js:180:9)
my-app_1 | name: 'MongoError',
my-app_1 | message: 'failed to connect to server [mongodb:27017] on first connect [MongoError: getaddrinfo ENOTFOUND mongodb mongodb:27017]' }
my-app_1 |
my-app_1 | If you are the maintainer of "createManager", then you can change its implementation to solve the problem (Most of the time, the solution is just to throw an actual Error instance instead. Alternatively, if the goal was to indicate a particular exception, you could throw any of the special, reserved "exit signals"-- e.g. the code name of any of your defined exits besides "error" or "success"). Otherwise, please file a bug report with the maintainer, or fork your own copy and fix that.
my-app_1 | [?] See https://sailsjs.com/support for help.
my-app_1 | at Object.registerDatastore (/usr/src/app/node_modules/sails-mongo/lib/index.js:263:18)
my-app_1 | at /usr/src/app/node_modules/waterline/lib/waterline.js:714:27
my-app_1 | at /usr/src/app/node_modules/async/dist/async.js:3047:20
my-app_1 | at eachOfArrayLike (/usr/src/app/node_modules/async/dist/async.js:1002:13)
my-app_1 | at eachOf (/usr/src/app/node_modules/async/dist/async.js:1052:9)
my-app_1 | at Object.eachLimit (/usr/src/app/node_modules/async/dist/async.js:3111:7)
my-app_1 | at Object.initialize (/usr/src/app/node_modules/waterline/lib/waterline.js:650:11)
my-app_1 | at buildOntologyAndRunAutoMigrations (/usr/src/app/node_modules/sails-hook-orm/lib/build-ontology-and-run-auto-migrations.js:55:7)
my-app_1 | at async.auto._buildOntology (/usr/src/app/node_modules/sails-hook-orm/lib/initialize.js:456:7)
my-app_1 | at runTask (/usr/src/app/node_modules/async/dist/async.js:1660:17)
my-app_1 | at /usr/src/app/node_modules/async/dist/async.js:1602:17
my-app_1 | at processQueue (/usr/src/app/node_modules/async/dist/async.js:1612:17)
my-app_1 | at taskComplete (/usr/src/app/node_modules/async/dist/async.js:1630:13)
my-app_1 | at /usr/src/app/node_modules/async/dist/async.js:1653:21
my-app_1 | at /usr/src/app/node_modules/async/dist/async.js:339:31
my-app_1 | at /usr/src/app/node_modules/async/dist/async.js:847:20
my-app_1 | ```
my-app_1 | at Object.error (/usr/src/app/node_modules/sails-mongo/lib/index.js:268:21)
my-app_1 | at /usr/src/app/node_modules/machine/lib/private/help-build-machine.js:1514:39
my-app_1 | at proceedToFinalAfterExecLC (/usr/src/app/node_modules/parley/lib/private/Deferred.js:1149:14)
my-app_1 | at proceedToInterceptsAndChecks (/usr/src/app/node_modules/parley/lib/private/Deferred.js:909:12)
my-app_1 | at proceedToAfterExecSpinlocks (/usr/src/app/node_modules/parley/lib/private/Deferred.js:841:10)
my-app_1 | at /usr/src/app/node_modules/parley/lib/private/Deferred.js:303:7
my-app_1 | at /usr/src/app/node_modules/machine/lib/private/help-build-machine.js:952:35
my-app_1 | at Function.handlerCbs.error (/usr/src/app/node_modules/machine/lib/private/help-build-machine.js:742:26)
my-app_1 | at connectCb (/usr/src/app/node_modules/sails-mongo/lib/private/machines/create-manager.js:130:22)
my-app_1 | at connectCallback (/usr/src/app/node_modules/mongodb/lib/mongo_client.js:428:5)
my-app_1 | at /usr/src/app/node_modules/mongodb/lib/mongo_client.js:335:11
my-app_1 | at _combinedTickCallback (internal/process/next_tick.js:131:7)
my-app_1 | at process._tickCallback (internal/process/next_tick.js:180:9)

这是我的/config/datastores.js 文件的样子:

module.exports.datastores = {

default: {
adapter: 'sails-mongo',
url: 'mongodb://mongoDb:27017/my-app',
ssl: false
},
};

我还根据 the Sails.js documentation 修改了/config/models.js :

attributes: {
createdAt: { type: 'number', autoCreatedAt: true, },
updatedAt: { type: 'number', autoUpdatedAt: true, },
id: { type: 'string', columnName: '_id' },
},

这是我的配置:

  • Node 8.9.4
  • NPM 5.6.0
  • 风 sails 1.0.2
  • sails-mongo 1.0.1

值得注意的是,我在一个 Docker 容器中运行应用程序(我使用了一个类似的容器来安装过去版本的 Sails,没有任何问题)。我将如何解决这个问题?我似乎无法在其他地方找到任何解决方案。谢谢。

更新:

这是我的 docker-compose.yml 文件的样子:

version: '3.4'

services:
server:
image: my-app:latest
build: .
environment:
NODE_ENV: development
RUNNING_LOCALLY: isRunningLocally
ports:
- 1340:1337 # HOST_PORT is 1339 to avoid conflicts with other Sails.js apps running on host
volumes:
- ../:/usr/src/app
entrypoint: nodemon

mongoDb:
image: mongo:3.6
ports:
- 27018:27017 # HOST_PORT is 27018 to avoid conflicts with other MongoDB databases running on host
volumes:
- ../../web-service/volumes/mongodb:/data/db # Since we want to use the same database as the web service

最佳答案

尝试在 docker-compose.yml 文件中将 MongoDB 服务的名称从 mongoDb 更改为 mongodb

由于此错误消息:MongoError: failed to connect to server [mongodb:27017] on first connect [MongoError: getaddrinfo ENOTFOUND mongodb mongodb:27017],在我看来 Sails.js 1.0.2 在 ./config/datastores.js - 'mongodb://mongoDb:27017/my 中的连接 URL 上运行 toLowerCase() -app'.

您的 server 容器可以访问 mongoDb 容器中的 MongoDB。通过运行 toLowerCase(),Sails.js 1.0.2 尝试连接到 mongodb 容器中的 MongoDB(mongodb 容器不存在,这就是它不起作用的原因)。

此外,不要忘记将您的 URL 连接从 mongodb://mongoDb:27017/my-app 更改为 mongodb://mongodb:27017/my-app.

关于javascript - Sails.js "Could not tear down ORM hook"错误与 sails-mongo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51148710/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com