Sails: 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.

Created on 18 Feb 2019  Â·  23Comments  Â·  Source: balderdashy/sails

Sails version: '^1.1.0'
Node version: 'v10.14.0'
NPM version: '6.7.0'
DB adapter name: 'sails-mongo'
DB adapter version: '^1.0.1'
Operating system: Window 10 64bits




Hello, I am trying to configure the atlas database in sails. But it does not work, my settings:

datastores: {
    default: {
      adapter: 'sails-mongo',
      url: 'mongodb://user:[email protected]:27017,cluster0-shard-00-01-2eqgk.mongodb.net:27017,cluster0-shard-00-02-2eqgk.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true',
      ssl: true
  },
}

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 (D:\interactr\code\videonudos-admin-back\node_modules\sails-mongo\lib\index.js:390:19)
at D:\interactr\code\videonudos-admin-back\node_modules\waterline\lib\waterline.js:758:27
at D:\interactr\code\videonudos-admin-back\node_modules\async\dist\async.js:3047:20
at eachOfArrayLike (D:\interactr\code\videonudos-admin-back\node_modules\async\dist\async.js:1002:13)
at eachOf (D:\interactr\code\videonudos-admin-back\node_modules\async\dist\async.js:1052:9)
at Object.eachLimit (D:\interactr\code\videonudos-admin-back\node_modules\async\dist\async.js:3111:7)
at Object.teardown (D:\interactr\code\videonudos-admin-back\node_modules\waterline\lib\waterline.js:742:11)
at Hook.teardown (D:\interactr\code\videonudos-admin-back\node_modules\sails-hook-orm\index.js:246:30)
at Sails.wrapper (D:\interactr\code\videonudos-admin-back\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 (D:\interactr\code\videonudos-admin-back\node_modules\sails\lib\app\private\after.js:56:26)
at D:\interactr\code\videonudos-admin-back\node_modules\sails\lib\app\lower.js:67:11
at beforeShutdown (D:\interactr\code\videonudos-admin-back\node_modules\sails\lib\app\lower.js:45:12)
at Sails.lower (D:\interactr\code\videonudos-admin-back\node_modules\sails\lib\app\lower.js:49:3)
at Sails.wrapper [as lower] (D:\interactr\code\videonudos-admin-back\node_modules\@sailshq\lodash\lib\index.js:3275:19)
error: Failed to lift app: Error: Consistency violation: Unexpected error creating db connection manager:

ImplementationError: Internal error occurred while running `createManager`.  Got non-Error: { MongoError: connection 5 to cluster0-shard-00-02-2eqgk.mongodb.net:27017 closed
    at Function.MongoError.create (D:\interactr\code\videonudos-admin-back\node_modules\mongodb-core\lib\error.js:29:11)
    at Socket.<anonymous> (D:\interactr\code\videonudos-admin-back\node_modules\mongodb-core\lib\connection\connection.js:202:22)
    at Object.onceWrapper (events.js:273:13)
    at Socket.emit (events.js:182:13)
    at Socket.EventEmitter.emit (domain.js:442:20)
    at TCP._handle.close (net.js:606:12)
  name: 'MongoError',
  message:
   'connection 5 to cluster0-shard-00-02-2eqgk.mongodb.net:27017 closed' }

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.
 [?] See https://sailsjs.com/support for help.
    at flaverr (D:\interactr\code\videonudos-admin-back\node_modules\flaverr\index.js:94:15)
    at Function.handlerCbs.error (D:\interactr\code\videonudos-admin-back\node_modules\machine\lib\private\help-build-machine.js:720:29)
    at connectCb (D:\interactr\code\videonudos-admin-back\node_modules\sails-mongo\lib\private\machines\create-manager.js:130:22)
    at connectCallback (D:\interactr\code\videonudos-admin-back\node_modules\mongodb\lib\mongo_client.js:428:5)
    at D:\interactr\code\videonudos-admin-back\node_modules\mongodb\lib\mongo_client.js:335:11
    at process._tickCallback (internal/process/next_tick.js:61:11)

at Object.error (D:\interactr\code\videonudos-admin-back\node_modules\sails-mongo\lib\index.js:268:21)
at D:\interactr\code\videonudos-admin-back\node_modules\machine\lib\private\help-build-machine.js:1514:39
at proceedToFinalAfterExecLC (D:\interactr\code\videonudos-admin-back\node_modules\parley\lib\private\Deferred.js:1149:14)
at proceedToInterceptsAndChecks (D:\interactr\code\videonudos-admin-back\node_modules\parley\lib\private\Deferred.js:909:12)
at proceedToAfterExecSpinlocks (D:\interactr\code\videonudos-admin-back\node_modules\parley\lib\private\Deferred.js:841:10)
at D:\interactr\code\videonudos-admin-back\node_modules\parley\lib\private\Deferred.js:303:7
at D:\interactr\code\videonudos-admin-back\node_modules\machine\lib\private\help-build-machine.js:952:35
at Function.handlerCbs.error (D:\interactr\code\videonudos-admin-back\node_modules\machine\lib\private\help-build-machine.js:742:26)
at connectCb (D:\interactr\code\videonudos-admin-back\node_modules\sails-mongo\lib\private\machines\create-manager.js:130:22)
at connectCallback (D:\interactr\code\videonudos-admin-back\node_modules\mongodb\lib\mongo_client.js:428:5)
at D:\interactr\code\videonudos-admin-back\node_modules\mongodb\lib\mongo_client.js:335:11
at process._tickCallback (internal/process/next_tick.js:61:11)

helpful info or workaround mongo orm

Most helpful comment

If you login to Mongo Atlas and select "Connect" for the cluster then select "Connect Your Application" then Node.js and finally select version 2.2.12. The connection string provided for 3.0 or later did not work.

Connection string (2.2.12 or later) :
mongodb://:@abc-cluster0-shard-00-00-f1efl.azure.mongodb.net:27017,abc-cluster0-shard-00-01-f1efl.azure.mongodb.net:27017,abc-cluster0-shard-00-02-f1efl.azure.mongodb.net:27017/?ssl=true&replicaSet=ABC-CLUSTER0-shard-0&authSource=admin&retryWrites=true&w=majority

All 23 comments

Hi @markos0886! It looks like you missed a step or two when you created your issue. Please edit your comment (use the pencil icon at the top-right corner of the comment box) and fix the following:

  • Verify "I am experiencing a concrete technical issue (aka a bug) with Sails (ideas and feature proposals should follow the guide for proposing features and enhancements (http://bit.ly/sails-feature-guide), which involves making a pull request). If you're not 100% certain whether it's a bug or not, that's okay--you may continue. The worst that can happen is that the issue will be closed and we'll point you in the right direction."
  • Verify "I am not asking a question about how to use Sails or about whether or not Sails has a certain feature (please refer to the documentation(http://sailsjs.com), or post on http://stackoverflow.com, our Google Group (http://bit.ly/sails-google-group) or our live chat (https://gitter.im/balderdashy/sails)."
  • Verify "I have already searched for related issues, and found none open (if you found a related _closed_ issue, please link to it in your post)."
  • Verify "My issue title is concise, on-topic and polite ("jst.js being removed from layout.ejs on lift" is good; "templates dont work" or "why is sails dumb" are not so good)."
  • Verify "I have tried all the following (if relevant) and my issue remains:"
  • Verify "I can provide steps to reproduce this issue that others can follow."

As soon as those items are rectified, post a new comment (e.g. “Ok, fixed!”) below and we'll take a look. Thanks!

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]

Hi @markos0886,
I was looking into your issue and also got the same error when using want you provided. On a closer look I think maybe its your connection URL that needs some re-configuring.
Here are the docs for that for some reference!

Hi @raqem, I verified that the connection was correctly using Studio 3t, it's fine the url. Maybe the problem is the replicaset, Before jumping to atlas, my database was in mlab and it worked correctly.

Apparently in Atlas it is used by default and provided a URL like this mongodb+srv://<user>:<password>@devspeeder-8ousb.gcp.mongodb.net/test?retryWrites=true to create the connection, but Sails does not seem to recognize this connection string.

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 (D:\Projetos\Speeder\WEBSERVICE\node_modules\sails-mongo\lib\index.js:390:19)
    at D:\Projetos\Speeder\WEBSERVICE\node_modules\waterline\lib\waterline.js:758:27
    at D:\Projetos\Speeder\WEBSERVICE\node_modules\waterline\node_modules\async\dist\async.js:3047:20
    at eachOfArrayLike (D:\Projetos\Speeder\WEBSERVICE\node_modules\waterline\node_modules\async\dist\async.js:1002:13)
    at eachOf (D:\Projetos\Speeder\WEBSERVICE\node_modules\waterline\node_modules\async\dist\async.js:1052:9)
    at Object.eachLimit (D:\Projetos\Speeder\WEBSERVICE\node_modules\waterline\node_modules\async\dist\async.js:3111:7)
    at Object.teardown (D:\Projetos\Speeder\WEBSERVICE\node_modules\waterline\lib\waterline.js:742:11)
    at Hook.teardown (D:\Projetos\Speeder\WEBSERVICE\node_modules\sails-hook-orm\index.js:246:30)
    at Sails.wrapper (D:\Projetos\Speeder\WEBSERVICE\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 (D:\Projetos\Speeder\WEBSERVICE\node_modules\sails\lib\app\private\after.js:56:26)
    at D:\Projetos\Speeder\WEBSERVICE\node_modules\sails\lib\app\lower.js:67:11
    at beforeShutdown (D:\Projetos\Speeder\WEBSERVICE\node_modules\sails\lib\app\lower.js:45:12)
    at Sails.lower (D:\Projetos\Speeder\WEBSERVICE\node_modules\sails\lib\app\lower.js:49:3)
    at Sails.wrapper [as lower] (D:\Projetos\Speeder\WEBSERVICE\node_modules\@sailshq\lodash\lib\index.js:3275:19)
error: Failed to lift app: Error: Invalid configuration for datastore `default`:  Provided URL ('mongodb+srv://speederroot:<password>@devspeeder-8ousb.gcp.mongodb.net/test?retryWrites=true') has an invalid protocol.
If included, the protocol must be "mongodb://".
--
(See http://sailsjs.com/config/datastores#?the-connection-url for more info.)
    at Object.registerDatastore (D:\Projetos\Speeder\WEBSERVICE\node_modules\sails-mongo\lib\index.js:209:58)
    at D:\Projetos\Speeder\WEBSERVICE\node_modules\waterline\lib\waterline.js:714:27
    at D:\Projetos\Speeder\WEBSERVICE\node_modules\waterline\node_modules\async\dist\async.js:3047:20
    at eachOfArrayLike (D:\Projetos\Speeder\WEBSERVICE\node_modules\waterline\node_modules\async\dist\async.js:1002:13)
    at eachOf (D:\Projetos\Speeder\WEBSERVICE\node_modules\waterline\node_modules\async\dist\async.js:1052:9)
    at Object.eachLimit (D:\Projetos\Speeder\WEBSERVICE\node_modules\waterline\node_modules\async\dist\async.js:3111:7)
    at Object.initialize (D:\Projetos\Speeder\WEBSERVICE\node_modules\waterline\lib\waterline.js:650:11)
    at buildOntologyAndRunAutoMigrations (D:\Projetos\Speeder\WEBSERVICE\node_modules\sails-hook-orm\lib\build-ontology-and-run-auto-migrations.js:55:7)
    at async.auto._buildOntology (D:\Projetos\Speeder\WEBSERVICE\node_modules\sails-hook-orm\lib\initialize.js:456:7)
    at runTask (D:\Projetos\Speeder\WEBSERVICE\node_modules\sails-hook-orm\node_modules\async\dist\async.js:1660:17)
    at D:\Projetos\Speeder\WEBSERVICE\node_modules\sails-hook-orm\node_modules\async\dist\async.js:1602:17
    at processQueue (D:\Projetos\Speeder\WEBSERVICE\node_modules\sails-hook-orm\node_modules\async\dist\async.js:1612:17)
    at taskComplete (D:\Projetos\Speeder\WEBSERVICE\node_modules\sails-hook-orm\node_modules\async\dist\async.js:1630:13)
    at D:\Projetos\Speeder\WEBSERVICE\node_modules\sails-hook-orm\node_modules\async\dist\async.js:1653:21
    at D:\Projetos\Speeder\WEBSERVICE\node_modules\sails-hook-orm\node_modules\async\dist\async.js:339:31
    at D:\Projetos\Speeder\WEBSERVICE\node_modules\sails-hook-orm\node_modules\async\dist\async.js:847:20

@adba @markos0886, my suspicion is that the URL formatting cant be read by Sails. It is suggested in the docs to make the URL yourself
image
using this format: protocol://user:password@host:port/database

I dont have any experience with Mongo or Atlas in particular, sorry I cant help more.

Hello @adba @raqem, in MongoDB Atlas there are two ways to make the connection to a replicaSet, using mongodb + srv or the old way mongodb: //
If you look at the configuration of my url I use the old one,
_

url: 'mongodb://user:[email protected]:27017,cluster0-shard-00-01-2eqgk.mongodb.net:27017,cluster0-shard-00-02-2eqgk.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true',

_

So the question would be, does Sails 1.0 support replicaSet in any way ?, because it is not in the documentation.

@markos0886 It really worked as you reported it however has a parameter (retryWrites: true) that Sails does not recognize I removed it and it worked normally using the mode you passed.

// It works

default: {
      adapter: 'sails-mongo',
      url: 'mongodb://<user>:<pass>@devspeeder-shard-00-00-8ousb.gcp.mongodb.net:27017,devspeeder-shard-00-01-8ousb.gcp.mongodb.net:27017,devspeeder-shard-00-02-8ousb.gcp.mongodb.net:27017/test',
      ssl: true,
      replicaSet:'DEVSpeeder-shard-0',
      authSource:'admin',
},

// It not works

default: {
      adapter: 'sails-mongo',
      url: 'mongodb://<user>:<pass>@devspeeder-shard-00-00-8ousb.gcp.mongodb.net:27017,devspeeder-shard-00-01-8ousb.gcp.mongodb.net:27017,devspeeder-shard-00-02-8ousb.gcp.mongodb.net:27017/test',
      ssl: true,
      replicaSet:'DEVSpeeder-shard-0',
      authSource:'admin',
      retryWrites: true // THIS HERE GENERATES AN ERROR IN SAILS
},

Hi @abalad thank you for offer a work around! @markos0886 Have you found his suggestion to be helpful? Or did you find another way to get Atlas connected?

Yeah happened to me too. Just use:

    adapter: 'sails-mongo',
    host: 'localhost',
    port: '27017',
    user: 'user',
    password: 'password',
    database: 'dbname'

Instead of the URL.

I struggled to find the replicaSet name for my cluster. You can find the steps here

I'm currently facing this same issue and non of this above solutions seems to work for me

NOTE::: I notice that i get this errors every time i disconnect my PC from the internet...

info: ·• Auto-migrating... (alter) info: Hold tight, this could take a moment. 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 (C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\sails-mongo\lib\index.js:390:19)
at C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\waterline\lib\waterline.js:758:27
at C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\waterline\node_modules\async\dist\async.js:3047:20
at eachOfArrayLike (C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\waterline\node_modules\async\dist\async.js:1002:13)
at eachOf (C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\waterline\node_modules\async\dist\async.js:1052:9)
at Object.eachLimit (C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\waterline\node_modules\async\dist\async.js:3111:7)
at Object.teardown (C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\waterline\lib\waterline.js:742:11)
at Hook.teardown (C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\sails-hook-orm\index.js:246:30)
at Sails.wrapper (C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\@sailshq\lodash\lib\index.js:3275:19)
at Object.onceWrapper (events.js:313:30)
at emitNone (events.js:106:13)
at Sails.emit (events.js:208:7)
at Sails.emitter.emit (C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\sails\lib\app\private\after.js:56:26)
at C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\sails\lib\app\lower.js:67:11
at beforeShutdown (C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\sails\lib\app\lower.js:45:12)
at Sails.lower (C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\sails\lib\app\lower.js:49:3)
at Sails.wrapper [as lower] (C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\@sailshq\lodash\lib\index.js:3275:19)
at whenSailsIsReady (C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\sails\lib\app\lift.js:68:13)
at C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\sails\node_modules\async\dist\async.js:3861:9
at C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\sails\node_modules\async\dist\async.js:421:16
at iterateeCallback (C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\sails\node_modules\async\dist\async.js:924:17)
at C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\sails\node_modules\async\dist\async.js:906:16
at C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\sails\node_modules\async\dist\async.js:3858:13
at C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\sails\lib\app\load.js:261:22
at C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\sails\node_modules\async\dist\async.js:421:16
at C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\sails\node_modules\async\dist\async.js:1609:17
at C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\sails\node_modules\async\dist\async.js:906:16
at C:\SIDE_PROJECTS\Development_hobbies\my-app\node_modules\sails\lib\app\load.js:186:25
error:
error: Error: Consistency violation: Unexpected error creating db connection manager:

MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: getaddrinfo ENOENT localhost:27017]
    at flaverr (C:\SIDE_PROJECTS\Development\_hobbies\my-app\node_modules\flaverr\index.js:94:15)
    at Function.module.exports.parseError (C:\SIDE_PROJECTS\Development\_hobbies\my-app\node_modules\flaverr\index.js:371:12)
    at Function.handlerCbs.error (C:\SIDE_PROJECTS\Development\_hobbies\my-app\node_modules\machine\lib\private\help-build-machine.js:665:56)
    at connectCb (C:\SIDE_PROJECTS\Development\_hobbies\my-app\node_modules\sails-mongo\lib\private\machines\create-manager.js:130:22)
    at connectCallback (C:\SIDE_PROJECTS\Development\_hobbies\my-app\node_modules\mongodb\lib\mongo_client.js:428:5)
    at C:\SIDE_PROJECTS\Development\_hobbies\my-app\node_modules\mongodb\lib\mongo_client.js:335:11
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickDomainCallback (internal/process/next_tick.js:218:9)
at Object.error (C:\SIDE_PROJECTS\Development\_hobbies\my-app\node_modules\sails-mongo\lib\index.js:268:21)
at C:\SIDE_PROJECTS\Development\_hobbies\my-app\node_modules\machine\lib\private\help-build-machine.js:1514:39
at proceedToFinalAfterExecLC (C:\SIDE_PROJECTS\Development\_hobbies\my-app\node_modules\parley\lib\private\Deferred.js:1153:14)
at proceedToInterceptsAndChecks (C:\SIDE_PROJECTS\Development\_hobbies\my-app\node_modules\parley\lib\private\Deferred.js:913:12)
at proceedToAfterExecSpinlocks (C:\SIDE_PROJECTS\Development\_hobbies\my-app\node_modules\parley\lib\private\Deferred.js:845:10)
at C:\SIDE_PROJECTS\Development\_hobbies\my-app\node_modules\parley\lib\private\Deferred.js:303:7
at C:\SIDE_PROJECTS\Development\_hobbies\my-app\node_modules\machine\lib\private\help-build-machine.js:952:35
at Function.handlerCbs.error (C:\SIDE_PROJECTS\Development\_hobbies\my-app\node_modules\machine\lib\private\help-build-machine.js:742:26)
at connectCb (C:\SIDE_PROJECTS\Development\_hobbies\my-app\node_modules\sails-mongo\lib\private\machines\create-manager.js:130:22)
at connectCallback (C:\SIDE_PROJECTS\Development\_hobbies\my-app\node_modules\mongodb\lib\mongo_client.js:428:5)
at C:\SIDE_PROJECTS\Development\_hobbies\my-app\node_modules\mongodb\lib\mongo_client.js:335:11
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)

`

My datastore configuration
default: { adapter: 'sails-mongo', host: 'localhost', port: '27017', database: 'hobby-app' },

My dependencies

"dependencies": {
    "@sailshq/connect-redis": "^3.2.1",
    "@sailshq/lodash": "^3.10.3",
    "@sailshq/socket.io-redis": "^5.2.0",
    "bcrypt": "^3.0.6",
    "body-parser": "^1.19.0",
    "cookie-parser": "^1.4.4",
    "dotenv": "^8.0.0",
    "grunt": "1.0.4",
    "jsonwebtoken": "^8.5.1",
    "passport": "^0.4.0",
    "passport-jwt": "^4.0.0",
    "passport-local": "^1.0.0",
    "sails": "^1.2.3",
    "sails-hook-grunt": "^4.0.0",
    "sails-hook-orm": "^2.1.1",
    "sails-hook-sockets": "^2.0.0",
    "sails-hook-validation": "^0.4.7",
    "sails-mongo": "^1.0.1"
  },

Hi, @TheDhejavu!

It looks like your error is coming from a failed DNS lookup. We think that this might be a MongoDB thing, and using 127.0.0.1 instead of localhost could solve the problem. Give that a shot, and let us know!

Thanks @madisonhicks , it worked....

Hi , i have tried all of the steps mentioned above, but i still get the error, it would be helpful if some one clear the error here.

module.exports.datastores = {

dbname: {

adapter: 'sails-mongo',
host: 'localhost',
port: '27017',
user: 'user',
password: 'password',
database: 'dbname'

}
};

error message

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 (dbname) 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/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/sails-mongo/lib/index.js:390:19)
at /Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/waterline/lib/waterline.js:758:27
at /Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/waterline/node_modules/async/dist/async.js:3047:20
at eachOfArrayLike (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/waterline/node_modules/async/dist/async.js:1002:13)
at eachOf (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/waterline/node_modules/async/dist/async.js:1052:9)
at Object.eachLimit (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/waterline/node_modules/async/dist/async.js:3111:7)
at Object.teardown (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/waterline/lib/waterline.js:742:11)
at Hook.teardown (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/sails-hook-orm/index.js:246:30)
at Sails.wrapper (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/@sailshq/lodash/lib/index.js:3282:19)
at Object.onceWrapper (events.js:272:13)
at Sails.emit (events.js:180:13)
at Sails.emit (domain.js:422:20)
at Sails.emitter.emit (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/sails/lib/app/private/after.js:56:26)
at /Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/sails/lib/app/lower.js:67:11
at beforeShutdown (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/sails/lib/app/lower.js:45:12)
at Sails.lower (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/sails/lib/app/lower.js:49:3)
at Sails.wrapper [as lower] (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/@sailshq/lodash/lib/index.js:3282:19)
at whenSailsIsReady (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/sails/lib/app/lift.js:68:13)
at /Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/sails/node_modules/async/dist/async.js:3861:9
at /Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/sails/node_modules/async/dist/async.js:421:16
at iterateeCallback (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/sails/node_modules/async/dist/async.js:924:17)
at /Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/sails/node_modules/async/dist/async.js:906:16
error:
error: Error: Consistency violation: Unexpected error creating db connection manager:

MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]
    at flaverr (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/flaverr/index.js:94:15)
    at Function.module.exports.parseError (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/flaverr/index.js:371:12)
    at Function.handlerCbs.error (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/machine/lib/private/help-build-machine.js:665:56)
    at connectCb (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/sails-mongo/lib/private/machines/create-manager.js:130:22)
    at connectCallback (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/mongodb/lib/mongo_client.js:428:5)
    at /Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/mongodb/lib/mongo_client.js:335:11
    at process._tickCallback (internal/process/next_tick.js:176:11)
at Object.error (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/sails-mongo/lib/index.js:268:21)
at /Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/machine/lib/private/help-build-machine.js:1514:39
at proceedToFinalAfterExecLC (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/parley/lib/private/Deferred.js:1153:14)
at proceedToInterceptsAndChecks (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/parley/lib/private/Deferred.js:913:12)
at proceedToAfterExecSpinlocks (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/parley/lib/private/Deferred.js:845:10)
at /Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/parley/lib/private/Deferred.js:303:7
at /Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/machine/lib/private/help-build-machine.js:952:35
at Function.handlerCbs.error (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/machine/lib/private/help-build-machine.js:742:26)
at connectCb (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/sails-mongo/lib/private/machines/create-manager.js:130:22)
at connectCallback (/Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/mongodb/lib/mongo_client.js:428:5)
at /Users/finahas/studies/theOdinProject/studies/sailsJS/project1/todolist/node_modules/mongodb/lib/mongo_client.js:335:11
at process._tickCallback (internal/process/next_tick.js:176:11)

error: Could not load Sails app.
error:
error: Tips:
error: • First, take a look at the error message above.
error: • Make sure you've installed dependencies with npm install.
error: • Check that this app was built for a compatible version of Sails.
error: • Have a question or need help? (http://sailsjs.com/support)

Hey, @finahas!

Your error looks a lot like the error @TheDhejavu was getting, which wound up arising from a failed DNS lookup. Have you tried using 127.0.0.1 instead of localhost? I only ask because the config you shared looks like it's got host: 'localhost'.

Same problem here. Should we treat coma separated values as a solution for now?

url: 'mongodb://<login>:<pass>@scorer-shard-00-00-3qy1y.azure.mongodb.net:27017,scorer-shard-00-01-3qy1y.azure.mongodb.net:27017,scorer-shard-00-02-3qy1y.azure.mongodb.net:27017/test?ssl=true&replicaSet=Scorer-shard-0&authSource=admin&retryWrites=true&w=majority'
More to it, I use custom Mongo client in the same app for more complicated operations, and it connects and works fine!

If you login to Mongo Atlas and select "Connect" for the cluster then select "Connect Your Application" then Node.js and finally select version 2.2.12. The connection string provided for 3.0 or later did not work.

Connection string (2.2.12 or later) :
mongodb://:@abc-cluster0-shard-00-00-f1efl.azure.mongodb.net:27017,abc-cluster0-shard-00-01-f1efl.azure.mongodb.net:27017,abc-cluster0-shard-00-02-f1efl.azure.mongodb.net:27017/?ssl=true&replicaSet=ABC-CLUSTER0-shard-0&authSource=admin&retryWrites=true&w=majority

@troyscott Does it provide a specific error message for the connection issue?

@troyscott as stated above, remove the retryWrites=true part of the connection uri. It is currently not supported by the mongo adapter.

@johnabrams7 I think you should try to rework the error that are thrown when wrongly setting the connection uri. It feel s like the first error shown is
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.)

Which does not means much, and the real error is hidden bellow without color, so it is easily missed. We should try to make the real error

Failed to lift app: Error: Invalid configuration for datastoredefault: Unrecognized options (retryWrites) specified as config overrides. This adapter expects only whitelisted properties.
more apparent.

@LouAdrien Yes I agree, we've been discussing ideas to make it easier to see the real error/cause of the ORM hook issue - everyone is welcome to share ideas / thoughts on ways to improve it (higher location / color / etc).

@troyscott @solovieff @finahas @TheDhejavu @saccodd @glemiere @markos0886 @abalad
In the meantime, I wanted to let everyone know we have a new version of sails-mongo 1.1.0 released yesterday with official driver support expanded to Mongo 3.6 + enhanced overall functionality & compatibility. Enjoy!

Whatever conclusion I get from the net and this page & that worked for me!

adapter: 'sails-mongo',
url: 'mongodb://<-user->:<-pass->@cluster-0-shard-00-00-dnb3s.mongodb.net:27017,cluster-0-shard-00-01-dnb3s.mongodb.net:27017,cluster-0-shard-00-02-dnb3s.mongodb.net:27017/<-dbName->',
ssl: true,
replicaSet: 'Cluster-0-shard-0',
authSource: 'admin',

_Working -_

  • mongodb://

_Not Working -_

  • mongodb+srv://
  • If you use adapter: 'connect-mongo' in session.js to hold session object _(Have to disable it)_

Hi, @TheDhejavu!

It looks like your error is coming from a failed DNS lookup. We think that this might be a MongoDB thing, and using 127.0.0.1 instead of localhost could solve the problem. Give that a shot, and let us know!

It's Working

If you login to Mongo Atlas and select "Connect" for the cluster then select "Connect Your Application" then Node.js and finally select version 2.2.12. The connection string provided for 3.0 or later did not work.

Connection string (2.2.12 or later) :
mongodb://:@abc-cluster0-shard-00-00-f1efl.azure.mongodb.net:27017,abc-cluster0-shard-00-01-f1efl.azure.mongodb.net:27017,abc-cluster0-shard-00-02-f1efl.azure.mongodb.net:27017/?ssl=true&replicaSet=ABC-CLUSTER0-shard-0&authSource=admin&retryWrites=true&w=majority

this works for me

Was this page helpful?
0 / 5 - 0 ratings