最近、ラップトップで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
},
};
Sails.jsのドキュメントに従って/config/models.jsも変更しました。
attributes: {
createdAt: { type: 'number', autoCreatedAt: true, },
updatedAt: { type: 'number', autoUpdatedAt: true, },
id: { type: 'string', columnName: '_id' },
},
これは私の構成がどのように見えるかです:
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
以下からのMongoDBサービスの名前を変更しようmongoDb
とmongodb
してdocker-compose.yml
ファイル。
このエラーメッセージが原因で:MongoError: failed to connect to server [mongodb:27017] on first connect [MongoError: getaddrinfo ENOTFOUND mongodb mongodb:27017]
、Sails.js1.0.2toLowerCase()
は./config/datastores.js
-にある接続URLで実行されているよう'mongodb://mongoDb:27017/my-app'
です。
あなたのserver
コンテナはであるMongoDBのへのアクセスがあるmongoDb
コンテナを。toLowerCase()
Sails.jsを実行することにより、1.0.2はmongodb
コンテナー内にあるMongoDBへの接続を試みます(mongodb
コンテナーが存在しないため、機能しません)。
また、URL接続をからmongodb://mongoDb:27017/my-app
に変更することを忘れないでくださいmongodb://mongodb:27017/my-app
。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加