Context deadline exceeded using mongo-driver and documentDB

180 views Asked by At

Hi Im newbee on golang applications, and Im facing the next error [SOME_IDS_1000_ELEMENTS]: connection(localhost:27017[-4]) incomplete read of message header: context deadline exceeded This happened after update mongo-driver libraries. Before I was using mongo-driver v1.3.2 but now I'm updating to 1.5.1 version and after that update I got that error, before with previous version it worked well, is there something new that changed in the driver?

Below is a simple snippetcode.

 client, err := mongo.NewClient(options.Client().ApplyURI(uri))
  if err != nil {
   log.Fatal(err)
  }
  db := s.DBClient.Database("MY_DATABASE")
  ctx, cancel := context.WithTimeout(context.Background(), 300*time.Second)
  defer cancel()
  coll := db.Collection("my_collections")
  filter := bson.M{
    "_id": bson.M{"$in": [SOME_IDS_1000_ELEMENTS]},
  }
  cur, err := coll.Find(ctx, filter)
  if err != nil {
   log.Printf("Error:::: %v", err)
    
  }

I tried to increase the time from 300 to 1000 it works but Im not sure than that could be a good solution

0

There are 0 answers