Sails-mongo not working with 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图集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'

用DB配置和Enjoy替换正确的值。

您也可以尝试使用sails 的sails mongo cloud npm包

最新更新