connecting to MongoDB replica set with monk in node.js

722 Views Asked by At

when I do this in monk

var monk = require('monk')
var db = monk('10.25.125.20/mydb')

it works fine, but when I do this

var monk = require('monk')
var db = monk('10.25.125.20/mydb,10.25.125.22')

it throws an error with the message: "database names cannot contain the character '.' " what am I doing wrong?

The IP addresses, are computers in my LAN, running the MongoDB instances, configured as a replica set, they are actually three nodes, but the third is an arbiter

this is what is what goes out to stderr

/home/user/Dev/project2/node_modules/monk/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/db.js:233
    if(databaseName.indexOf(invalidChars[i]) != -1) throw new Error("database 
                                                          ^
Error: database names cannot contain the character '.'
    at validateDatabaseName (/home/user/Dev/project2/node_modules/monk/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/db.js:233:59)
    at new Db (/home/user/Dev/project2/node_modules/monk/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/db.js:95:3)
    at connectFunction (/home/user/Dev/project2/node_modules/monk/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/mongo_client.js:243:29)
    at Function.MongoClient.connect (/home/user/Dev/project2/node_modules/monk/node_modules/mongoskin/node_modules/mongodb/lib/mongodb/mongo_client.js:313:5)
    at SkinClass.SkinDb._open (/home/user/Dev/project2/node_modules/monk/node_modules/mongoskin/lib/db.js:36:25)
    at SkinClass.open (/home/user/Dev/project2/node_modules/monk/node_modules/mongoskin/lib/utils.js:162:14)
    at new Manager (/home/user/Dev/project2/node_modules/monk/lib/manager.js:65:15)
    at Manager (/home/user/Dev/project2/node_modules/monk/lib/manager.js:32:12)
    at Object.<anonymous> (/home/user/Dev/project2/config/mongo.js:18:10)
    at Module._compile (module.js:456:26)
error: Forever detected script exited with code: 8
1

There are 1 best solutions below

0
On

DB Name and set ID at the end:

mongodb://10.25.125.20:portnr,10.25.125.22:portnr/mydb?replicaSet=<rsname>