Delay in get query mongodb replica set

Viewed 23

I have a replica set with two members which are working fine except one thing that is when I add something and immediately gets it then it does not return the data, it seems the post query is executed on primary and get on secondary which does not have data yet. How can I fix this issue so that I am able to get data immediately after adding it.

I am using golang mongo package and following is my function

ctx = context.Background()
serverAuth := options.Credential{}
serverAuth.AuthSource = "admin"
ipPort := ipport
    serverAuth.Username = username
    serverAuth.Password = password 
serverAuth.PasswordSet = true
opts := options.Client().ApplyURI("mongodb://" + ipPort).SetConnectTimeout(5 * time.Second).SetAuth(serverAuth)
    opts = opts.SetWriteConcern(writeconcern.New(writeconcern.WMajority()))
client, err := mongo.Connect(ctx, opts)

if err != nil {
    fmt.Println("CreateSession: "+prjName, err)
    client.Disconnect(ctx)
    return
}
return
0 Answers
Related