Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

When connecting to a replica set, the options field will not accept a poolSize #1144

Closed
zaneclaes opened this Issue · 5 comments

3 participants

@zaneclaes

The following works correctly, to create a connection with a poolSize:
mongoose.connect('mongodb://localhost:27017', {server:{poolSize:5}});

This also works correctly, to connect to a replica set:
mongoose.connect('mongodb://localhost:27017,mongodb://localhost:27018,mongodb://localhost:27019');

However, when the two are combined, to connect to a replica set with a poolSize:
mongoose.connect('mongodb://localhost:27017,mongodb://localhost:27018,mongodb://localhost:27019', {server:{poolSize:5}});

The following error results:
Uncaught Exception:Error: database name must be a string
at validateDatabaseName (/usr/lib/nodejs/mongoose/node_modules/mongodb/lib/mongodb/db.js:237:46)
at new Db (/usr/lib/nodejs/mongoose/node_modules/mongodb/lib/mongodb/db.js:79:3)
at NativeConnection.doOpenSet (/usr/lib/nodejs/mongoose/lib/drivers/node-mongodb-native/connection.js:107:15)
at NativeConnection._open (/usr/lib/nodejs/mongoose/lib/connection.js:361:14)
at NativeConnection.openSet (/usr/lib/nodejs/mongoose/lib/connection.js:323:8)
at Mongoose.connect (/usr/lib/nodejs/mongoose/lib/index.js:148:18)

@aheckmann
Owner

the error is actually correct, the first two examples are broken. a database name is required in the connection string.

need to patch the connection string validation logic.

anyway, to get you going again add the database to the connection string:
mongoose.connect('mongodb://localhost:27017/DATABASE_NAME,mongodb://localhost:27018,mongodb://localhost:27019', {server:{poolSize:5}});

@zaneclaes

You code works, unless I add a callback (3rd parameter)... in which case, the same error (above) continues.

@aheckmann aheckmann closed this in 1b20a6f
@jplock

I'm not sure if this has been fixed. I'm now getting this error:

/appl/myapp/node_modules/mongoose/lib/connection.js:615
  if (!('auto_reconnect' in o.server)) {
                             ^
TypeError: Cannot use 'in' operator to search for 'auto_reconnect' in undefined
    at NativeConnection.Connection.defaultOptions (/appl/myapp/node_modules/mongoose/lib/connection.js:615:30)
    at NativeConnection.Connection.openSet (/appl/myapp/node_modules/mongoose/lib/connection.js:297:33)
    at Mongoose.connect (/appl/myapp/node_modules/mongoose/lib/index.js:148:18)
    at mongoConnect (/appl/myapp/myapp/app.js:95:18)
    at Object.<anonymous> (/appl/myapp/myapp/app.js:113:1)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)

after upgrading to 3.3.0. I'm calling mongoose.connect() like:

var options = {
        'db': {
            'native_parser': true
        },
        'server': {
            'auto_reconnect': true,
            'poolSize': 10
        },
        'replset': {
            'readPreference': 'nearest',
            'strategy': 'ping',
            'rs_name': 'mySet'
        }
    };
mongoose.connect(uris, 'mydb', options);
@jplock

I'm reading the docs now (http://mongoosejs.com/docs/connections.html), and it doesn't look like mongoose.connect() supports passing the database name as the 2nd parameter. I am including the database name in my uris, so I should be ok. The only reason I'm pointing this out is because this used to work prior to 3.3.0 so I'm not sure if it was an intended BC break or not.

@aheckmann
Owner

thanks for the heads up. fixed in 3.3.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.