[GODRIVER-1537] Set read concern/read preference for individual operations Created: 19/Mar/20  Updated: 27/Mar/23

Status: Backlog
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Georgy Savva Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I need to run a find query with read preference and read concern different from the defaults for the collection/database/client. How can I set it using the go library. 

In a shell it looks like that:

```
db.restaurants.find(

{ _id: 5 }

).readConcern("majority").readPref("secondary")
```
 



 Comments   
Comment by Georgy Savva [ 26/Mar/20 ]

Thanks, It will help so far.

Comment by Isabella Siu (Inactive) [ 24/Mar/20 ]

Hi georgy.savva@gmail.com,

For now, you can use Clone to create a new Collection object from an existing Collection object with some different options: 

coll1 := client.Database("test").Collection("restaurants")
coll2, err := coll1.Clone(
  options.Collection().
  SetReadConcern(readconcern.Majority()).
  SetReadPreference(readpref.Secondary()))
if err != nil {
  //handle error
}
cur, err := coll2.Find(context.Background(), bson.D{{"_id", 5}})

 We will also open this ticket as a new feature to add in the future.

Generated at Thu Feb 08 08:36:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.