[CSHARP-2114] MongoIndexManager always read indexes from primary Created: 27/Nov/17 Updated: 27/Oct/23 Resolved: 23/Jan/18 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Read Operations |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Minor - P4 |
| Reporter: | Artem Zinenko | Assignee: | Robert Stam |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
MongoIndexManager methods List and ListAsync don't use client read preference settings, always read list of indexes from primary:
|
| Comments |
| Comment by Robert Stam [ 23/Jan/18 ] |
|
You could probably use a direct connection to the secondary. Direct connections to a single server ignore read preference. |
| Comment by Artem Zinenko [ 27/Nov/17 ] |
I'm connecting directly to the secondary, my connection string is "mongodb://secondaryHost/db?readPreference=secondary" (also have tried "mongodb://secondaryHost/db").
I understand that all read operations from secondary doesn't necessarily give up-to-date information. But I would like to manage it myself. |
| Comment by Craig Wilson [ 27/Nov/17 ] |
|
I believe it's because checking indexes on a secondary doesn't necessarily give up-to-date information. The only reason to really check indexes would be to take action upon information discovered, in which case it might not be up-to-date. If you are connecting directly to a secondary (i.e. not to a replica set), this should work as the specification has accommodation for this. How are you connecting to the secondary? |
| Comment by Artem Zinenko [ 27/Nov/17 ] |
|
Hi Craig, Thank you for your response. It's very interesting that listIndexes can be run on a secondary, but always must run on primary. Do you know the reasons for that decision? In my case, I have access only to the secondary node and want to use that node for all my read operations (that's why I use "readPreference=secondary" in my connection string). But I can't, driver fails with TimeoutException because it can't connect to primary. |
| Comment by Craig Wilson [ 27/Nov/17 ] |
|
Hi Artem, The specification for indexes requires that we always use a primary (https://github.com/mongodb/specifications/blob/master/source/enumerate-indexes.rst#replicasets). Why do you want it to use a secondary? |
| Comment by Artem Zinenko [ 27/Nov/17 ] |