Javascript Sails.js“;无法拆掉ORM挂钩“;蒙戈帆船的错误
我最近在笔记本电脑上将Sails从0.12升级到1.0.2,并启动了一个新项目。我试图使用sails mongo连接到MongoDB数据库,但出现以下错误:Javascript Sails.js“;无法拆掉ORM挂钩“;蒙戈帆船的错误,javascript,node.js,sails.js,sails-mongo,Javascript,Node.js,Sails.js,Sails Mongo,我最近在笔记本电脑上将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 dow
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/models.js:
这就是我的配置:
module.exports.datastores = {
default: {
adapter: 'sails-mongo',
url: 'mongodb://mongoDb:27017/my-app',
ssl: false
},
};
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
- 节点8.9.4
- NPM 5.6.0
- 帆1.0.2
- 风帆mongo 1.0.1
module.exports.datastores = {
default: {
adapter: 'sails-mongo',
url: 'mongodb://mongoDb:27017/my-app',
ssl: false
},
};
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:在第一次连接[MongoError:getaddrinfo-ENOTFOUND-mongodb-mongodb:27017]时未能连接到服务器[mongodb:27017]
,在我看来,Sails.js 1.0.2运行的似乎是toLowerCase()
在/config/datastores.js
-中的连接URL上mongodb://mongoDb:27017/my-应用程序“
您的服务器
容器可以访问MongoDB
容器中的MongoDB。通过运行toLowerCase()
Sails.js 1.0.2尝试连接到MongoDB
容器中的MongoDB(该MongoDB
容器不存在,这就是它不工作的原因)
另外,不要忘记从
mongodb://mongoDb:27017/my-应用程序
至mongodb://mongodb:27017/my-app
你能显示你的Docker配置吗(Dockerfile
或Docker compose.yml
)?@VladyslavTurak用Docker-compose.yml文件更新了我的问题