I continuously get the following error when attempting to connect to my MongoDB Atlas database.
no reachable servers
exit status 1
I am running MongoDB version 3.4, which is compatible with mgo.
I have whitelisted all IP addresses on MongoDB Atlas, including my own.
I have created a user named 'root'
on MongoDB Atlas with admin rights.
I am running on Ubuntu 18.04, and I have set my DNS Nameserver to 8.8.8.8.
I am using the Community supported version of mgo
from github.com/globalsign/mgo
.
My code is as follows:
package main
import (
"fmt"
"log"
"github.com/globalsign/mgo"
"github.com/globalsign/mgo/bson"
)
func main() {
database := "bookstore"
collection := "books"
user := "root"
pword := "root"
url := "mongodb://" + user + ":" + pword + "@<prefix>.mongodb.net:27017/" + database + "?w=majority"
session, err := mgo.Dial(url)
if err != nil {
log.Fatal(err)
} else {
fmt.Println("Success.")
}
}
I have looked at the following questions. These do not solve my problem:
CreateSession: no reachable servers - mgo
How to solve panic: no reachable servers
Connecting to MongoDB Atlas using Golang mgo: Persistent no reachable server to replica set
Golang / MGO -- panic: no reachable servers
No reachable servers on static linked go binary
Go and MongoDB connection won't work with panic log "no reachable server"
No reachable servers on static linked go binary
How to use new URL from mongodb 3.6 to connect from golang
How to connect to remote Mongodb server
Any help is truly appreciated!