I'm not able to lift a Sails api application in a production environment on Heroku to connect against a mongolab db. This works well when running in a local setup. The Heroku logs shows the following...
`
/app/node_modules/mongodb/lib/server.js:235
process.nextTick(function() { throw err; })
^
TypeError: Cannot read property 'close' of undefined
at /app/node_modules/sails-mongo/lib/adapter.js:138:13
at /app/node_modules/sails-mongo/node_modules/async/lib/async.js:187:20
at /app/node_modules/sails-mongo/node_modules/async/lib/async.js:239:13
at _arrayEach (/app/node_modules/sails-mongo/node_modules/async/lib/async.js:91:13)
at _each (/app/node_modules/sails-mongo/node_modules/async/lib/async.js:82:13)
at Object.async.forEachOf.async.eachOf (/app/node_modules/sails-mongo/node_modules/async/lib/async.js:238:9)
at Object.async.forEach.async.each (/app/node_modules/sails-mongo/node_modules/async/lib/async.js:215:22)
at Object.module.exports.adapter.teardown (/app/node_modules/sails-mongo/lib/adapter.js:137:22)
at /app/node_modules/sails/lib/hooks/orm/index.js:244:19
at /app/node_modules/async/lib/async.js:122:13
at _each (/app/node_modules/async/lib/async.js:46:13)
at Object.async.each (/app/node_modules/async/lib/async.js:121:9)
at Sails.hook.teardown (/app/node_modules/sails/lib/hooks/orm/index.js:241:13)
at Sails.g (events.js:260:16)
at emitNone (events.js:67:13)
at Sails.emit (events.js:166:7)
`
Running sails version 0.11.2
Sails-mongo version 0.11.4
The process.env variables has been added and verified
connection.js
`
mongodb: {
adapter: 'sails-mongo',
url : process.env.CONNECTION_URL,
host: process.env.DB_HOST,
port: process.env.PORT_NR,
user: proces.env.USER,
password: process.env.PASSWORD,
database: process.env.DB
},
` env/production.js
`
connections : {
mongoLive: {
adapter: 'sails-mongo',
url : process.env.CONNECTION_URL
}
},
models: {
connection: 'mongoLive'
},
`
development.js
`
connections : {
mongoDev: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
database: 'threads_db'
}
},
models: {
connection: 'mongoDev'
}
`
Procfile
`
web: npm start
`
package.json
`
"scripts": {
"debug": "node debug app.js",
"start": "sails lift"
},
`
models.js has been set to
`
connection: 'mongodb',
`
So, running this locally works fine with both a connection to a local mongo db and the remote mongolab db but deployment to Heroku fails. Sees to me that I'm missing something in the setup. Help with this appreciated.
I resolved this by using the master version of sails-mongo.
package.json
"sails": "git+https://github.com/balderdashy/sails.git"
Then once deployed to heroku restarted the dyno with
`heroku ps:scale web=1`