1602/express-on-railway — Issue #64: JugglingDB / RailwayJS generator Mongoose config mismatch
Author: MartinodF
Created: 2011-11-02 15:36:13+00:00
State: open

The RailwayJS Mongoose config generator creates an object with a `host` parameter:

"development": {
"driver": "mongoose"
, "host": "localhost"
, "database": "APPNAME-dev"
}

RailwayJS (develop branch) passes that config object down to JugglingDB [here](https://github.com/1602/express-on-railway/blob/develop/lib/models.js#L91) which sets the object as `.settings` on the Schema object [here](https://github.com/1602/jugglingdb/blob/master/lib/schema.js#L28).

However, the Mongoose adapter in JugglingDB expects an `.url` parameter instead of `.host` ([see here](https://github.com/1602/jugglingdb/blob/master/lib/adapters/mongoose.js#L7)).

Long story short, using the development branch of RailwayJS with Mongoose, the server (clean, just created by `rw init`) crashes when it tries to connect to MongoDB:

node.js:134
throw e; // process.nextTick error, or 'error' event on first tick
^
TypeError: Cannot read property 'length' of undefined
at Object.urlParse [as parse] (url.js:94:27)
at NativeConnection.open (/home/mart/Repos/cereals/node_modules/railway/node_modules/jugglingdb/node_modules/mongoose/lib/connection.js:120:21)
at Mongoose.connect (/home/mart/Repos/cereals/node_modules/railway/node_modules/jugglingdb/node_modules/mongoose/lib/index.js:104:24)
at Object.initializeSchema [as initialize] (/home/mart/Repos/cereals/node_modules/railway/node_modules/jugglingdb/lib/adapters/mongoose.js:7:30)
at new Schema (/home/mart/Repos/cereals/node_modules/railway/node_modules/jugglingdb/lib/schema.js:47:13)
at Object.init (/home/mart/Repos/cereals/node_modules/railway/lib/models.js:91:18)
at Array. (/home/mart/Repos/cereals/node_modules/railway/lib/onrailway.js:71:24)
at EventEmitter._tickCallback (node.js:126:26)

You need to either change the generator to use a full `url` (such as `mongodb://localhost[:port][/db]`), or to make the JugglingDB Schema object assemble an `url` parameter using `host`, `port`, `db` from the config object.

I'm not sure what would be the most appropriate choice, otherwise I would have submitted a pull request :)