[CSHARP-335] MongoCollection.Count() method does not respect SlaveOk Created: 05/Oct/11 Updated: 02/Apr/15 Resolved: 06/Oct/11 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 1.2 |
| Fix Version/s: | 1.3 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Alan L. | Assignee: | Robert Stam |
| Resolution: | Done | Votes: | 0 |
| Labels: | replication | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Description |
|
mongoDB Setup Sample Code:
I can get the collection of items fine from taskCollection.FindAll(), but if I call taskCollection.Count(), driver throws the following error: MongoDB.Driver.MongoConnectionException: Unable to connect to the primary member of the replica set: No connection could be made because the target machine actively refused it Some troubleshooting leads me to believe the MongoCollection.Count() implementation is not respecting the SlaveOk setting. |
| Comments |
| Comment by Robert Stam [ 06/Oct/11 ] |
|
See |
| Comment by Robert Stam [ 06/Oct/11 ] |
|
I'm opening a new issue ( |
| Comment by Robert Stam [ 06/Oct/11 ] |
|
You are correct. Count is actually executed as a command, and all commands are sent to the primary. Many commands only work on the primary. While count theoretically could be sent to a secondary, the driver doesn't know (at least not yet) on a command by command case whether that particular command could be sent to the secondary. You could work around this by working at a lower level and sending the equivalent query to the $cmd collection using FindOne, in which case slaveOk would be honored. Let me know if you are interested in doing that and need help writing it that way. |