[JAVA-1877] readPreference and db commands Created: 29/Jun/15 Updated: 11/Sep/19 Resolved: 30/Jun/15 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Command Operations |
| Affects Version/s: | 3.0.0, 3.0.2 |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Marco Bonezzi | Assignee: | Unassigned |
| Resolution: | Done | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Hi, It looks like the readPreference for a db command is not always working as expected. 1 case:
This is the document used:
If this {{//geoQuery.append("$readPreference", new Document("mode", "nearest")) }} is commented, the queries will always go to the primary. 2nd case:
The node performing the queries is checked by using db.setLogLevel(3) and looking at the commands on each node. If any other information is required please let me know. Thank you, Regards, Marco |
| Comments |
| Comment by Marco Bonezzi [ 30/Jun/15 ] |
|
Hi Jeff, Thanks for your reply! The issue was related to a sharded cluster + replica set, where all geoNear commands were going to the primary. Unfortunately in a sharded collection $near cannot be used, which would have simplified the situation. Thank you for the clarification on this, I believe this ticket can now be marked as solved. Kind Regards, |
| Comment by Jeffrey Yemin [ 29/Jun/15 ] |
|
Hi Marko, I think you're running in to The other option would be to use a normal query using the $near operator, as the driver will respect the configured read preference for normal queries. The reasons for the generic command method of MongoDatabase to ignore the default read preference are enumerated in the server selection specification. See the section titled "General command method going to primary". |