-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 1.0.1
-
Component/s: None
-
None
Go Version: 1.12.5
I have this code which uses the node.js mongo driver
const MongoClient = require('mongodb').MongoClient;
const uri = process.env.MONGO_HOST + "dbname?retryWrites=true";
const client = new MongoClient(uri,
);
client.connect(async (err) => {
if (err)
const collection = client.db("dbname").collection("collectionName");
const cursor = collection.find()
await cursor.forEach(console.log)
// perform actions on the collection object
client.close();
});
Which works fine.
Using the `mongo-go-driver`, I do:
client, err := mongo.NewClient(options.Client().ApplyURI(os.Getenv("MONGO_HOST") + "dbname?retryWrites=true")
if err != nil
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
err = client.Connect(ctx)
if err != nil { panic(err) }
database := client.Database("dbname")
collection := database.Collection("collectionName")
res, err := collection.Find(context.Background(), bson.M{}, &options.FindOptions{
Sort: bson.M
,
})
if err != nil
results := make([]structs.ResponseType, 0)
err = res.All(context.Background(), &results)
if err != nil { panic(err) }
But this panics with:
panic: server selection error: server selection timeout
current topology: Type: ReplicaSetNoPrimary
I am not running this inside a container/docker.
- duplicates
-
GODRIVER-1032 MongoDB Atlas CommandNotFound with Updated Go Driver
- Closed