Hello Semia, The mgo library you’re referencing has this text at top of the repository:
The MongoDB driver for Go. UNMAINTAINED - SEE BELOW The implication of that statement is that the library may not work for newer versions of MongoDB and the error you’re experiencing could be a result of that. The package author recommends other packages to use listed in the repository such as a community fork of mgo. Another recommended solution is to use the official Go driver for MongoDB at https://github.com/mongodb/mongo-go-driver The official documentation has a guide for connecting to MongoDB here https://www.mongodb.com/docs/drivers/go/current/fundamentals/connections/connection-guide/ Kind regards, Uzondu On Mon, 17 Feb 2025 at 19:52, SEMIA GUESMI <semia.gue...@unicam.it> wrote: > Dears, > > Hi, > > I have a question regarding the MongoDB package for Go (mgo). > > I have installed MongoDB and confirmed that it is running. However, when I > try to connect to it using Go, I consistently get the following error: *"No > reachable servers"* > > I would appreciate any guidance on how to resolve this issue. > > Best, > > Semia > package main > > import ( > "fmt" > "log" > > "gopkg.in/mgo.v2" > ) > > func main() { > fmt.Println("Attempting to connect to MongoDB...") > > session, err := mgo.Dial("mongodb://localhost:27017") > if err != nil { > log.Fatal("MongoDB connection failed: ", err) > } > defer session.Close() > > fmt.Println("MongoDB connected successfully!") > } > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com. > To view this discussion visit > https://groups.google.com/d/msgid/golang-nuts/b7e7c5c9-700d-44b9-a46c-e7b64a4fadcdn%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/b7e7c5c9-700d-44b9-a46c-e7b64a4fadcdn%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion visit https://groups.google.com/d/msgid/golang-nuts/CAHwjp7gFqu9b3hXXYmzvos2ViLV3iRVSOUc78SXTUjsriYOiAQ%40mail.gmail.com.