0

I am new to using SailsJS and also I am using mongodb for the database to connect. I tried using Robo 3T to make sure that my connection is valid and check that the models are in it. However, when I tried lifting using sails lift I encountered this error:

error: A hook (`orm`) failed to load!
error:
error: Error: Consistency violation: A model (`calendar`) references a datastore which cannot be found (`warboard-test`).  If this
 model definition has an explicit `connection` property, check that it is spelled correctly.  If not, check your default `connecti
on` (usually located in `config/models.js`).  Finally, check that this connection (`warboard-test`) is valid as per http://sailsjs
.org/documentation/reference/configuration/sails-config-connections.
    at validateModelDef (G:\projects\htdocs\warboard\node_modules\sails-hook-orm\lib\validate-model-def.js:110:11)
    at G:\projects\htdocs\warboard\node_modules\sails-hook-orm\lib\initialize.js:218:36
    at arrayEach (G:\projects\htdocs\warboard\node_modules\sails-hook-orm\node_modules\lodash\index.js:1289:13)
    at Function.<anonymous> (G:\projects\htdocs\warboard\node_modules\sails-hook-orm\node_modules\lodash\index.js:3345:13)
    at Array.async.auto._normalizeModelDefs (G:\projects\htdocs\warboard\node_modules\sails-hook-orm\lib\initialize.js:216:11)
    at listener (G:\projects\htdocs\warboard\node_modules\async\lib\async.js:605:42)
    at G:\projects\htdocs\warboard\node_modules\async\lib\async.js:544:17
    at _arrayEach (G:\projects\htdocs\warboard\node_modules\async\lib\async.js:85:13)
    at Immediate.taskComplete [as _onImmediate] (G:\projects\htdocs\warboard\node_modules\async\lib\async.js:543:13)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)

error: Could not load Sails app.
error:
error: Tips:
error:   First, take a look at the error message above.
error:   Check that you're using the latest stable version of Sails.
error:   Have a question or need help?  (http://sailsjs.com/support)

I am pretty sure that I have a Calendar model and also it exists on my mongodb through GUI.

This is my config/connections.js:

module.exports.connections = {
localDiskDb: {
  adapter: 'sails-disk'
},
dbTest: {
    adapter: 'sails-mongo',
    url: 'mongodb://user:password@host:port/db?replicaSet=rs-ds117073',
    socketOptions: {
      keepAlive: 1000,
      connectTimeoutMS: 60000
    }
  }
};

My config/models.js:

module.exports.models = {
 connection: 'db-test',
 migrate: 'alter',
 migrations: true,
 version: 3
};

Sails: 1.0.0-46 Node: 8.9.4

Does anyone encounter this error?

Thanks in advance!

the_lorem_ipsum_guy
  • 452
  • 1
  • 12
  • 27
  • 1
    Is there a disconnect between your dashed notation (`db-test`) and camel case (`dbTest`)? You use dashed in your `config/models.js` and the other in your `config/connections.js`. – arbuthnott Feb 26 '18 at 13:12
  • Also, in `/api/models/Calendar.js` do you set a `connection` property? – arbuthnott Feb 26 '18 at 13:12
  • @arbuthnott ahh I see! I thought you should input the `dbTest` method instead of the name of the database. I've tried it and it is already working but new issue which is `Server failed to start. (received error: EADDRINUSE) – the_lorem_ipsum_guy Feb 26 '18 at 13:42
  • now it works! I was running the `pm2` service and kill it because it conflicts with the port. Thanks! You can put your answer in the comment section so that I can accept it as the answer. – the_lorem_ipsum_guy Feb 26 '18 at 13:51
  • Glad you got it working - yes, we have all become familiar with that EADDRINUSE error :) – arbuthnott Feb 26 '18 at 13:54

1 Answers1

2

You have to change the line in config/models.js from:

connection: 'db-test', // no match in connections.js

to:

connection: 'dbTest', // matches a key in connections.js

Then it will match the key name you give in your config/connections.js file.

arbuthnott
  • 3,819
  • 2
  • 8
  • 21