node.js - Sails-mongo 不使用 MongoDB Atlas URI
问题描述
我正在尝试使用以下配置:
在datastores.js
我试过
adapter: 'sails-mongo',
url: 'mongodb+srv://xyz@cluster0.uaxyh.mongodb.net/xyz?retryWrites=true&w=majority',
ssl: true
以上 URL 用于 MongoDB Atlas
在model.js
id: { type: 'string', columnName: '_id' }
做过npm install sails-mongo
我仍然无法连接到我的“MongoDB”
我正在使用"sails": "^1.2.4"
, "sails-mongo": "^1.2.0"
为了您的信息,我想告诉您,我能够使用Mongoose
适配器连接到同一个实例。
我得到的错误如下 -
A hook (`orm`) failed to load!
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.)
Error: Consistency violation: Unexpected error creating db connection manager:
MongoError: failed to connect to server [cluster0.uzpih.mongodb.net:27017] on first connect
[MongoError: getaddrinfo ENOTFOUND cluster0.uzpih.mongodb.net cluster0.uzpih.mongodb.net:27017]
请建议我在哪里做错了!提前致谢
解决方案
您可以在MongoDB atlas connection
选项卡中找到正确的 URL,您可以在其中选择nodejs
驱动程序版本2.2.12 or later
以下网址对我有用:
url: 'mongodb://USER:PASSWORD@DB01-shard-00-00-yxtfo.mongodb.net:27017,DB01-shard-00-01-yxtfo.mongodb.net:27017,DB01-shard-00-02-yxtfo.mongodb.net:27017/DB?ssl=true&replicaSet=DB01-shard-0&authSource=admin&retryWrites=true&w=majority'
用您的数据库配置替换正确的值并享受。
推荐阅读
- visual-studio - 如何在最新的 cppwinrt 中 co_await GetFilesAsync?
- python - Flask-CQLAlchemy DB 对象没有“查询”属性
- javascript - 自定义指令将子文本推送到数组中
- java - 泛型类型如何为 getter 和 setter 工作?
- java - StanfordNLP 分类器内存不足错误
- python - Unix shell 上的 python 中的 sys.stdin
- firebase - Firestore 安全性:拒绝更新/写入请求资源中的字段(在模拟器中工作,而不是 IRL)
- tfs - TFS 2017 测试用例历史
- scala - 连接多个数据框的功能方式
- linux - 是否有适用于 Windows 和 Linux 的 vscode 片段路径变量?