javascript - 在 Sails 版本 1 中使用sails-mongo 时无法加载钩子(`orm`)
问题描述
Sails 版本:1.2.3
节点版本:v10.14.2
Sails Mongo 版本:1.0.1
数据存储配置:
default: {
adapter: 'sails-mongo',
url:
'mongodb://user:password@xxx.xxx.xxx.xxx:27017/user_db'
密码由特殊字符组成,如
#!_-
. 那是问题吗?由于某些原因,即使将带有特殊字符的密码更改为适当的密码,仍然无法连接。
我期待在没有用户名和密码的情况下使用 localhost 建立连接的帮助。如何构造这样的连接字符串?
error: A hook (`orm`) failed to load!
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.)
at Object.teardown (/Users/apple/Documents/projects/ozone-login-system/node_modules/sails-mongo/lib/index.js:390:19)
at /Users/apple/Documents/projects/ozone-login-system/node_modules/waterline/lib/waterline.js:758:27
at /Users/apple/Documents/projects/ozone-login-system/node_modules/waterline/node_modules/async/dist/async.js:3047:20
at eachOfArrayLike (/Users/apple/Documents/projects/ozone-login-system/node_modules/waterline/node_modules/async/dist/async.js:1002:13)
at eachOf (/Users/apple/Documents/projects/ozone-login-system/node_modules/waterline/node_modules/async/dist/async.js:1052:9)
at Object.eachLimit (/Users/apple/Documents/projects/ozone-login-system/node_modules/waterline/node_modules/async/dist/async.js:3111:7)
at Object.teardown (/Users/apple/Documents/projects/ozone-login-system/node_modules/waterline/lib/waterline.js:742:11)
at Hook.teardown (/Users/apple/Documents/projects/ozone-login-system/node_modules/sails-hook-orm/index.js:246:30)
at Sails.wrapper (/Users/apple/Documents/projects/ozone-login-system/node_modules/@sailshq/lodash/lib/index.js:3275:19)
at Object.onceWrapper (events.js:273:13)
at Sails.emit (events.js:182:13)
at Sails.emitter.emit (/Users/apple/Documents/projects/ozone-login-system/node_modules/sails/lib/app/private/after.js:56:26)
at /Users/apple/Documents/projects/ozone-login-system/node_modules/sails/lib/app/lower.js:67:11
at beforeShutdown (/Users/apple/Documents/projects/ozone-login-system/node_modules/sails/lib/app/lower.js:45:12)
at Sails.lower (/Users/apple/Documents/projects/ozone-login-system/node_modules/sails/lib/app/lower.js:49:3)
at Sails.wrapper [as lower] (/Users/apple/Documents/projects/ozone-login-system/node_modules/@sailshq/lodash/lib/index.js:3275:19)
error: Failed to lift app: Error: Consistency violation: Unexpected error creating db connection manager:
```
MongoError: Authentication failed.
at flaverr (/Users/apple/Documents/projects/ozone-login-system/node_modules/flaverr/index.js:94:15)
at Function.module.exports.parseError (/Users/apple/Documents/projects/ozone-login-system/node_modules/flaverr/index.js:371:12)
at Function.handlerCbs.error (/Users/apple/Documents/projects/ozone-login-system/node_modules/machine/lib/private/help-build-machine.js:665:56)
at connectCb (/Users/apple/Documents/projects/ozone-login-system/node_modules/sails-mongo/lib/private/machines/create-manager.js:130:22)
at connectCallback (/Users/apple/Documents/projects/ozone-login-system/node_modules/mongodb/lib/mongo_client.js:428:5)
at /Users/apple/Documents/projects/ozone-login-system/node_modules/mongodb/lib/mongo_client.js:376:13
at process._tickCallback (internal/process/next_tick.js:61:11)
```
at Object.error (/Users/apple/Documents/projects/ozone-login-system/node_modules/sails-mongo/lib/index.js:268:21)
at /Users/apple/Documents/projects/ozone-login-system/node_modules/machine/lib/private/help-build-machine.js:1514:39
at proceedToFinalAfterExecLC (/Users/apple/Documents/projects/ozone-login-system/node_modules/parley/lib/private/Deferred.js:1153:14)
at proceedToInterceptsAndChecks (/Users/apple/Documents/projects/ozone-login-system/node_modules/parley/lib/private/Deferred.js:913:12)
at proceedToAfterExecSpinlocks (/Users/apple/Documents/projects/ozone-login-system/node_modules/parley/lib/private/Deferred.js:845:10)
at /Users/apple/Documents/projects/ozone-login-system/node_modules/parley/lib/private/Deferred.js:303:7
at /Users/apple/Documents/projects/ozone-login-system/node_modules/machine/lib/private/help-build-machine.js:952:35
at Function.handlerCbs.error (/Users/apple/Documents/projects/ozone-login-system/node_modules/machine/lib/private/help-build-machine.js:742:26)
at connectCb (/Users/apple/Documents/projects/ozone-login-system/node_modules/sails-mongo/lib/private/machines/create-manager.js:130:22)
at connectCallback (/Users/apple/Documents/projects/ozone-login-system/node_modules/mongodb/lib/mongo_client.js:428:5)
at /Users/apple/Documents/projects/ozone-login-system/node_modules/mongodb/lsib/mongo_client.js:376:13
at process._tickCallback (internal/process/next_tick.js:61:11)
解决方案
如果您在 2020 年查看此内容,则需要使用较旧的 mongo-db url 设置将 mongo Atlas 连接到sails。
//config/datastores.js
default:
{ adapter: require('sails-mongo'),
url: "mongodb://<YOUR_USERNAME>:<YOUR_PASSWORD>@cluster0-shard-00-00-kiodk.mongodb.net:27017,cluster0-shard-00-01-kiodk.mongodb.net:27017,cluster0-shard-00-02-kiodk.mongodb.net:27017/<YOUR_DB_NAME>?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true&w=majority",
}
要使其与帆一起使用,您的 URL 应采用上述格式!
推荐阅读
- mysql - 防止 MySQL 用户创建/删除数据库
- python - 生产中的 Django i18n
- jenkins - 构建 json 在工件 UI 中不显示保留策略
- spring-boot - 在 application.properties 文件中配置自定义 Kafka Consumer Deserializer。[弹簧靴]
- python - 旋转大型数据框pyspark的最有效方法
- javascript - 每 5 秒检查/观察一次服务的变化并更新输出
- swift - 为 UIButton 创建发布者
- php - 由于插件与我的 Functions.php 冲突导致的 Wordpress 严重错误
- azure - Azure - 获取内部 IP 地址的资源 ID
- postgresql - PostgreSQL - 多个约束