I'm using mtools
to spin up a replica set with 3 nodes (mlaunch --replicaset
) on ports 27017, 27018, and 27019.
However I'm having difficulty actually connecting to the replica set using Dial
from the mgo package. The code snippet below panics with the message no reachable servers
:
type Person struct {
Name string `bson:"name"`
Age int `bson:"age"`
}
func main() {
session, err := mgo.Dial("localhost:27017,localhost:27018,localhost:27019")
if err != nil {
panic(err)
}
c := session.DB("mydb").C("testCollection")
c.Insert(&Person{Name: "Foo", Age: 20})
}
How exactly does one connect to a replica set using the mgo package?