2

I created a Sails.js app, it connects to local MongoDB correctly but if I want to connect it to cloud mongodb, Sails throws an error. what should I do to fix it?

default: {
    adapter: 'sails-mongo',
    // url: 'mongodb://localhost:27017/referral' // this work fine
    url: 'mongodb+srv://MYUSERNAME:MYPASS@cluster0.ikncs.mongodb.net/referral?retryWrites=true&w=majority'
  },

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

error: Error: Invalid configuration for datastore default: Provided URL ('mongodb+srv://MYUSERNAME:MYPASS@cluster0.ikncs.mongodb.net/referral?retryWrites=true&w=majority') has an invalid protocol. If included, the protocol must be "mongodb://".

I will appreciate if someone help quickly

S. V
  • 1,085
  • 5
  • 5

2 Answers2

3

I had a similar issue.

The connection string I got from Atlas was for Node version 3.0 or later did not work with the sails adapter.

But the connection string from Atlas for Node version 2.2.12 worked.

From Atlas, click connect -> Connect to your application (using MongoDB's Native Drivers) -> Select Node.js Version 2.2.12 or later. Use the connection string it provides.

Anthony
  • 192
  • 2
  • 8
  • thanks, Anthony, after changing url to 2.2/12 I am getting this error: Consistency violation: Unexpected error creating db connection manager – S. V Sep 05 '20 at 07:25
  • Would need the full error stack. Can you post another question? – Anthony Sep 05 '20 at 07:27
  • Yea I did, please check this link: https://stackoverflow.com/questions/63754995/sails-js-error-when-connect-to-cloud-mongodb – S. V Sep 05 '20 at 14:29
1

I have got the same issue, it’s due to mongodb version used in sails-mongo, for our production database we have worked on improving the existing package. You can search for sails-mongo-cloud in npm which supports cloud mongo atlas and cluster with server less setup as well.

Sandeep PC
  • 797
  • 8
  • 12